[翻译] 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



[翻译] TSMessages的更多相关文章
- 《Django By Example》第五章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者@ucag注:大家好,我是新来的翻译, ...
- 《Django By Example》第四章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:祝大家新年快乐,这次带来<D ...
- [翻译]开发文档:android Bitmap的高效使用
内容概述 本文内容来自开发文档"Traning > Displaying Bitmaps Efficiently",包括大尺寸Bitmap的高效加载,图片的异步加载和数据缓存 ...
- 【探索】机器指令翻译成 JavaScript
前言 前些时候研究脚本混淆时,打算先学一些「程序流程」相关的概念.为了不因太枯燥而放弃,决定想一个有趣的案例,可以边探索边学. 于是想了一个话题:尝试将机器指令 1:1 翻译 成 JavaScript ...
- 《Django By Example》第三章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:第三章滚烫出炉,大家请不要吐槽文中 ...
- 《Django By Example》第二章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:翻译完第一章后,发现翻译第二章的速 ...
- 《Django By Example》第一章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:本人目前在杭州某家互联网公司工作, ...
- 【翻译】Awesome R资源大全中文版来了,全球最火的R工具包一网打尽,超过300+工具,还在等什么?
0.前言 虽然很早就知道R被微软收购,也很早知道R在统计分析处理方面很强大,开始一直没有行动过...直到 直到12月初在微软技术大会,看到我软的工程师演示R的使用,我就震惊了,然后最近在网上到处了解和 ...
- ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第一章:创建基本的MVC Web站点
在这一章中,我们将学习如何使用基架快速搭建和运行一个简单的Microsoft ASP.NET MVC Web站点.在我们马上投入学习和编码之前,我们首先了解一些有关ASP.NET MVC和Entity ...
随机推荐
- golang闭包实现递归
func main() { for i := 1; i < 30; i++ { fmt.Println(Fibonacci(i)) } } func Fibonacci(n int) int { ...
- Mahout实战---评估推荐程序
推荐程序的一般评测标准有MAE(平均绝对误差),Precision(查准率),recall(查全率) 针对Mahout实战---运行第一个推荐引擎 的推荐程序,将使用上面三个标准分别测量 MAE(平均 ...
- Nodejs学习笔记(十三)—PM2
简介 PM2 pm2是一个内置负载均衡的node.js应用进程管理器(也支持Windows),其它的类似功能也有不少,但是感觉pm2功能更强,更值的推荐 GitHub地址:https://github ...
- Beta阶段——Scrum 冲刺博客第三天
一.当天站立式会议照片一张 二.每个人的工作 (有work item 的ID),并将其记录在码云项目管理中 昨天已完成的工作 实现部分question页面的制作,制作内容包括题目序号的制作,同时在最后 ...
- 设计模式学习--面向对象的5条设计原则之Liskov替换原则--LSP
一.LSP简介(LSP--Liskov Substitution Principle): 定义:如果对于类型S的每一个对象o1,都有一个类型T的对象o2,使对于任意用类型T定义的程序P,将o2替换为o ...
- JPA之@OneToMany、@ManyToOne、@JoinColumn
顾名思义,@OneToMany.@ManyToOne这两个注解就是处理一对多,多对一的关系 这两个注解是成双成对的,有了@OneToMany,一定会配置一个@ManyToOne OneToMany设置 ...
- Jsp&Servlet入门级项目全程实录第8讲
惯例广告一发,对于初学真,真的很有用www.java1234.com,去试试吧! 1.添加dao public int studentAdd(Connection con,Student studen ...
- [javaSE] 数组(排序-冒泡排序)
两层嵌套循环,外层控制循环次数,内层循环进行比较 for(int x=0;x<arr.length-1;x++){ for(int y=0;y<arr.length;y++){ if(ar ...
- Spring 、SpringMVC 、Struts2之间的区别
一.Spring与SpringMVC的区别: spring是一个开源框架,是为了解决企业应用程序开发,功能如下: 功能:使用基本的JavaBean代替EJB,并提供了更多的企业应用功能 范围:任何Ja ...
- 解决input为number类型时maxlength无效的问题
使用input数字number类型的时候maxlength无效,假设需要控制输入数量为18,可以用以下方式: 无效: <input type="text" maxlengt ...