TSMessages

TSMessages

https://github.com/KrauseFx/TSMessages

 

This library provides an easy to use class to show little notification views on the top of the screen. (à la Tweetbot).

这个库提供了一个用于提示的view,显示在屏幕上.

The notification moves from the top of the screen underneath the navigation bar and stays there for a few seconds, depending on the length of the displayed text. To dismiss a notification before the time runs out, the user can swipe it to the top or just tap it.

提示的view从屏幕上面的navigation bar上出现,呆上几秒钟(多长时间依赖于显示的文本的长度).然后自动消失,当然,你也可以通过点击这个view让其消失.

There are 4 different types already set up for you: Success, Error, Warning, Message (take a look at the screenshots)

有四种类型的样式供你选择:成功,失败,警告,消息.

It is very easy to add new notification types with a different design. Add the new type to the notificationType enum, add the needed design properties to the configuration file and set the name of the theme (used in the config file and images) in TSMessagesView.m inside the switch case.

添加新的样式也非常的简单.先在notificationType中添加新的枚举值,然后在配置文件中添加新的属性,以及对应的主题即可.

Take a look at the Example project to see how to use this library. You have to open the workspace, not the project file, since the Example project uses cocoapods.

你可以看看项目工程中是怎么使用的.因为是通过cocopods安装的,所以你需要打开workspace文件.

Get in contact with the developer on Twitter: KrauseFx (Felix Krause)

 

Installation

TSMessages is available through CocoaPods. To install it, simply add the following line to your Podfile:

你可以通过podfile安装,执行如下指令:

pod "TSMessages"

Copy the source files TSMessageView and TSMessage into your project. Also copy the TSMessagesDesignDefault.json.

或者是手动将文件TSMessageView与TSMessage拖到你的项目当中,然后拷贝TSMessagesDesignDefault.json文件.

 

Usage

To show notifications use the following code:

你可以按照以下方式进行使用:

    [TSMessage showNotificationWithTitle:@"Your Title"
                                subtitle:@"A description"
                                    type:TSMessageNotificationTypeError];

    // Add a button inside the message
    [TSMessage showNotificationInViewController:self
                                          title:@"Update available"
                                       subtitle:@"Please update the app"
                                          image:nil
                                           type:TSMessageNotificationTypeMessage
                                       duration:TSMessageNotificationDurationAutomatic
                                       callback:nil
                                    buttonTitle:@"Update"
                                 buttonCallback:^{
                                     NSLog(@"User tapped the button");
                                 }
                                     atPosition:TSMessageNotificationPositionTop
                           canBeDismissedByUser:YES];

    // Use a custom design file
    [TSMessage addCustomDesignFromFileWithName:@"AlternativeDesign.json"];

You can define a default view controller in which the notifications should be displayed:

你可以指定一个默认的控制器,然后在该控制器上显示出提示信息:

   [TSMessage setDefaultViewController:myNavController];

You can define a default view controller in which the notifications should be displayed:

 

   [TSMessage setDelegate:self];

   ...

   - (CGFloat)messageLocationOfMessageView:(TSMessageView *)messageView
   {
    return messageView.viewController...; // any calculation here
   }

You can customize a message view, right before it's displayed, like setting an alpha value, or adding a custom subview

你可以自定义一个信息的view,然后让他显示.

   [TSMessage setDelegate:self];

   ...

   - (void)customizeMessageView:(TSMessageView *)messageView
   {
      messageView.alpha = 0.4;
      [messageView addSubview:...];
   }

You can customize message view elements using UIAppearance

你也可以通过UIAppearance来定制信息的view

#import <TSMessages/TSMessageView.h>
@implementation TSAppDelegate
....

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//If you want you can overidde some properties using UIAppearance
[[TSMessageView appearance] setTitleFont:[UIFont boldSystemFontOfSize:6]];
[[TSMessageView appearance] setTitleTextColor:[UIColor redColor]];
[[TSMessageView appearance] setContentFont:[UIFont boldSystemFontOfSize:10]];
[[TSMessageView appearance]setContentTextColor:[UIColor greenColor]];
[[TSMessageView appearance]setErrorIcon:[UIImage imageNamed:@"NotificationButtonBackground"]];
[[TSMessageView appearance]setSuccessIcon:[UIImage imageNamed:@"NotificationButtonBackground"]];
[[TSMessageView appearance]setMessageIcon:[UIImage imageNamed:@"NotificationButtonBackground"]];
[[TSMessageView appearance]setWarningIcon:[UIImage imageNamed:@"NotificationButtonBackground"]];
//End of override

return YES;
}

The following properties can be set when creating a new notification:

你在创建一个新的提示view时,可以设置以下的属性:

  • viewController: The view controller to show the notification in. This might be the navigation controller.
  • title: The title of the notification view
  • subtitle: The text that is displayed underneath the title (optional)
  • image: A custom icon image that is used instead of the default one (optional)
  • type: The notification type (Message, Warning, Error, Success)
  • duration: The duration the notification should be displayed
  • callback: The block that should be executed, when the user dismissed the message by tapping on it or swiping it to the top.

Except the title and the notification type, all of the listed values are optional

除了标题以及提示的类型,其他都是可选的设置

If you don't want a detailed description (the text underneath the title) you don't need to set one. The notification will automatically resize itself properly.

如果你不想显示具体的提示信息,你不需要进行设置哦,提示的view会自己控制布局问题,不需要你担心.

 

Screenshots

 

时间: 2024-09-14 23:21:06

TSMessages的相关文章

史上最全的iOS开源项目分类汇总

楼主转载的,并未亲自测试 Category/Util  sstoolkit 一套Category类型的库,附带很多自定义控件 功能不错-        BFKit 又一套Category类型的 Kit,还有几个工具类        APUtils 又一套Category类型的 Kit        QSKit 又一套Category类型的 Kit        iOS-Categories 又一套Category类型的 Kit        BlocksKit 将Block风格带入UIKit和F

iOS开发-常用第三方开源框架介绍(你了解的ios只是冰山一角)

图像: 1.图片浏览控件MWPhotoBrowser        实现了一个照片浏览器类似 iOS 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网络下载图片并进行缓存.可对图片进行缩放等操作.       下载:https://github.com/mwaterfall/MWPhotoBrowser   目前比较活跃的社区仍旧是Github,除此以外也有一些不错的库散落在Google Code.SourceForge等地方.由于Github社区太过主流,这里主要介绍一下Gith

常用iOS的第三方框架

图像:1.图片浏览控件MWPhotoBrowser       实现了一个照片浏览器类似 iOS 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网络下载图片并进行缓存.可对图片进行缩放等操作.      下载:https://github.com/mwaterfall/MWPhotoBrowser 目前比较活跃的社区仍旧是Github,除此以外也有一些不错的库散落在Google Code.SourceForge等地方.由于Github社区太过主流,这里主要介绍一下Github里面流

开源 iOS 项目分类索引大全

mattt大神的发布程序:https://github.com/nomad/shenzhen ----------------Mac完整项目----------电台:https://github.com/myoula/sostart ----------------iOS完整项目----------------1,豆瓣相册 https://github.com/TonnyTao/DoubanAlbum2,voa在线英语 https://github.com/cubewang/NewsReader

IOS开发常见第三方总结

链接](https://github.com/languages​​/Objective-C/most_watched) * [three20](https://github.com/facebook/three20) * faebook的320库** * [AFNetworking](https://github.com/AFNetworking/AFNetworking) *网络库** * [MBProgressHUD](https://github.com/jdg/MBProgressHU

【转载】GitHub Top 100 简介(IOS框架)

GitHub Top 100 简介 主要对当前 GitHub 排名前 100 的项目做一个简单的简介, 方便初学者快速了解到当前 Objective-C 在 GitHub 的情况.              原文链接:https://github.com/Aufree/trip-to-iOS/blob/master/Top-100.md Android 版本的在此: https://github.com/Freelander/Android_Data/blob/master/Android-Li

iOS GitHub Top 100 简介

主要对当前 GitHub 排名前 100 的项目做一个简单的简介, 方便初学者快速了解到当前 Objective-C 在 GitHub 的情况. 项目名称 项目信息 1. AFNetworking 作者是 NSHipster 的博主, iOS 开发界的大神级人物, 毕业于卡内基·梅隆大学, 开源了许多牛逼的项目, 这个便是其中之一, AFNetworking 采用 NSURLConnection + NSOperation, 主要方便与服务端 API 进行数据交换, 操作简单, 功能强大, 现在