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

 

目录
相关文章
单细胞分析|映射和注释查询数据集
单细胞分析|映射和注释查询数据集
|
Web App开发 前端开发 JavaScript
27 个前端动画库让你的交互更加炫酷
很多时候我们在开发前端页面时都会做一些动画效果来提升用户体验度和页面美观度,所以今天就来给大家推荐几个好用的JavaScript动画库,希望对各位小伙伴有所帮助!
2927 0
|
11月前
|
存储 并行计算 C++
NVIDIA Triton系列08-用户端其他特性
本文详细解析了NVIDIA Triton开源项目的image_client.py示例代码,涵盖指定通信协议(HTTP与gRPC)、调用异步模式与数据流处理、以及使用共享内存等核心功能,为开发者提供撰写Triton用户端应用的指导。通过具体代码示例,帮助读者理解如何高效利用Triton服务器进行模型推理。
239 1
NVIDIA Triton系列08-用户端其他特性
|
8月前
|
NoSQL 关系型数据库 MySQL
阿里云PolarDB游戏场景最佳实践
阿里云PolarDB游戏场景最佳实践涵盖了数据库体系演进、行业优化、Redis解决方案、性能优化、备份还原及全球部署等内容。PolarDB通过共享存储、物理复制等技术提升读扩展和大容量支持,针对游戏行业的高IO需求进行优化,提供秒级备份与快速恢复能力。同时,PolarDB for Redis实现了一写多读架构,支持百TB级别的高性能存储,具备成本优势。该方案已在米哈游等大型游戏中广泛应用,确保了高并发下的稳定性和数据一致性,满足游戏行业的特殊需求。
329 36
|
9月前
|
定位技术 数据安全/隐私保护
如何评估HTTP代理IP的性能?
随着互联网技术的发展,使用代理IP的人越来越多。选择HTTP代理IP时,需注意速度和稳定性、用户信息保护、地域性、带宽上限、支持的协议、客户支持、用户评价和信誉、价格和性价比等方面。希望这些建议能帮助大家做出合适的选择。
137 1
|
机器学习/深度学习 人工智能 自然语言处理
【深度学习】python之人工智能应用篇——视频生成技术
视频生成技术是一种基于深度学习和机器学习的先进技术,它使得计算机能够根据给定的文本、图像、视频等单模态或多模态数据,自动生成符合描述的、高保真的视频内容。这种技术主要依赖于深度学习模型,如生成对抗网络(GAN)、自回归模型(Auto-regressive Model)、扩散模型(Diffusion Model)等。其中,GAN由两个神经网络组成:一个生成器用于生成逼真的图像或视频,另一个判别器用于判断生成的图像或视频是否真实。通过不断的对抗学习,生成器和判别器共同优化,以产生更高质量的视频。
508 2
|
缓存 负载均衡 监控
Nginx实现高并发
通过应用上述策略,可以大幅提高Nginx的并发处理能力,从而在面对高流量时,保持稳定、快速的服务响应。不断地监控和调优系统将有助于保持服务器性能的最优化。
255 3
|
SQL Java 数据库连接
【Java】已解决java.sql.SQLTimeoutException异常
【Java】已解决java.sql.SQLTimeoutException异常
426 0
|
开发工具 git
Git项目如何配置,如何上传至GitHub。其详细步骤
Git项目如何配置,如何上传至GitHub。其详细步骤
188 0