[翻译] 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 ...
随机推荐
- 解决iptables nat sctp协议无效的问题
环境组网如下: A----->B-----C IP如下: A:1.1.1.1 B:1.1.1.2; 2.2.2.1 C:2.2.2.2 需求为,A 需要使用sctp连通C 在B机器上添加ipta ...
- Chrome插件下载地址
www.crx4chrome.com可以直接下载 Chrome Store 插件 在chrome web store好像只能安装插件.
- PTA (Advanced Level) 1028 List Sorting
List Sorting Excel can sort records according to any column. Now you are supposed to imitate this fu ...
- Qt 绘图与动画系统
Qt 提供了内置的绘图系统以及独立的QtOpenGL模块提供对OpenGL的支持.Qt提供了基于状态机的QPainter系统和面向对象的Graphics View系统. QPainter 基于状态机的 ...
- springboot启动太慢优化
需求缘起:有人在[springboot]微信公众号问:springboot启动慢的问题何时有个分享就好了,谢谢.粉丝的问题还是要认真的回答的. 我们先看看本节的大纲: (1)组件自动扫描带来的问题(@ ...
- PHP 集成开发环境比较
专注了这么些年技术,没有养成记录和积累的习惯.如今乐于开源和分享经验,却停笔踌躇,不知该从何处说起.开通博客也有一段时间了,也没能写出一篇像样的文章,其实这篇文章也是被我拉壮丁似的用来练手的.思前想后 ...
- 数组的strong copy理解
一.数组的不同情况下的copy,mutablecopy分析 1.不可变数组的copy(没有创建新对象,复制的只是指针) 2.不可变数组的mutable copy(创建新对象) ...
- gRPC的通讯过程
在 HTTP2 协议正式开始工作前, 如果已经知道服务器是 HTTP2 的服务器, 通讯流程如下: 客户端必须首先发送一个连接序言,其逻辑结构: PRI * HTTP/2.0\r\n\r\nSM\r\ ...
- 高并发第八弹:J.U.C起航(java.util.concurrent)
java.util.concurrent是JDK自带的一个并发的包主要分为以下5部分: 并发工具类(tools) 显示锁(locks) 原子变量类(aotmic) 并发集合(collections) ...
- 项目Debug版本与Release版本的区别
Debug版本:通常称为调试版本,它包含调试信息,并且不作任何优化,便于程序员调试程序. Release版本:称为发布版本,它往往是进行了各种优化,使得程序在代码大小和运行速度上都是最优的,以便用户很 ...