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

 

目录
相关文章
|
3天前
|
Kubernetes 安全 Devops
【云效流水线 Flow 测评】驾驭云海:五大场景下的云效Flow实战部署评测
云效是一款企业级持续集成和持续交付工具,提供免费、高可用的服务,集成阿里云多种服务,支持蓝绿、分批、金丝雀等发布策略。其亮点包括快速定位问题、节省维护成本、丰富的企业级特性及与团队协作的契合。基础版和高级版分别针对小型企业和大规模团队,提供不同功能和服务。此外,云效对比Jenkins在集成阿里云服务和易用性上有优势。通过实战演示了云效在ECS和K8s上的快速部署流程,以及代码质量检测和AI智能排查功能,展示了其在DevOps流程中的高效和便捷,适合不同规模的企业使用。本文撰写用时5小时,请各位看官帮忙多多支持,如有建议也请一并给出,您的建议能帮助我下一篇更加出色。
|
9天前
|
机器学习/深度学习 数据采集 人工智能
人类生产力的解放?揭晓从大模型到AIGC的新魔法
本文从介绍大模型的概念延伸到大模型的革命意义。作者讲述了通过大模型的加持,让AIGC有了更多的可能性。
126708 3
|
8天前
|
存储 Prometheus 并行计算
10倍性能提升-SLS Prometheus 时序存储技术演进
本文将介绍近期SLS Prometheus存储引擎的技术更新,在兼容 PromQL 的基础上实现 10 倍以上的性能提升。同时技术升级带来的成本红利也将回馈给使用SLS 时序引擎的上万内外部客户。
89152 2
|
9天前
|
人工智能 弹性计算 算法
一文解读:阿里云AI基础设施的演进与挑战
对于如何更好地释放云上性能助力AIGC应用创新?“阿里云弹性计算为云上客户提供了ECS GPU DeepGPU增强工具包,帮助用户在云上高效地构建AI训练和AI推理基础设施,从而提高算力利用效率。”李鹏介绍到。目前,阿里云ECS DeepGPU已经帮助众多客户实现性能的大幅提升。其中,LLM微调训练场景下性能最高可提升80%,Stable Difussion推理场景下性能最高可提升60%。
|
9天前
|
机器人 Linux API
基于Ollama+AnythingLLM轻松打造本地大模型知识库
Ollama是开源工具,简化了在本地运行大型语言模型(ile优化模型运行,支持GPU使用和热加载。它轻量、易用,可在Mac和Linux上通过Docker快速部署。AnythingLLM是Mintplex Labs的文档聊天机器人,支持多用户、多种文档格式,提供对话和查询模式,内置向量数据库,可高效管理大模型和文档。它也是开源的,能与Ollama结合使用,提供安全、低成本的LLM体验。这两款工具旨在促进本地高效利用和管理LLMs。
139504 26
|
11天前
|
消息中间件 安全 API
Apache RocketMQ ACL 2.0 全新升级
RocketMQ ACL 2.0 不管是在模型设计、可扩展性方面,还是安全性和性能方面都进行了全新的升级。旨在能够为用户提供精细化的访问控制,同时,简化权限的配置流程。欢迎大家尝试体验新版本,并应用在生产环境中。
103851 1
|
11天前
|
Kubernetes Cloud Native 容灾
OpenKruise v1.6 版本解读:增强多域管理能力
OpenKruise 在 2024.3 发布了最新的 v1.6 版本(ChangeLog),本文对新版本的核心特性做整体介绍。
86565 1
|
14天前
|
物联网 PyTorch 测试技术
手把手教你捏一个自己的Agent
Modelscope AgentFabric是一个基于ModelScope-Agent的交互式智能体应用,用于方便地创建针对各种现实应用量身定制智能体,目前已经在生产级别落地。
|
16天前
|
NoSQL Cloud Native Redis
Redis核心开发者的新征程:阿里云与Valkey社区的技术融合与创新
阿里云瑶池数据库团队后续将持续参与Valkey社区,如过往在Redis社区一样耕耘,为开源社区作出持续贡献。
Redis核心开发者的新征程:阿里云与Valkey社区的技术融合与创新
|
16天前
|
关系型数据库 分布式数据库 数据库
PolarDB闪电助攻,《香肠派对》百亿好友关系实现毫秒级查询
PolarDB分布式版助力《香肠派对》实现百亿好友关系20万QPS的毫秒级查询。
PolarDB闪电助攻,《香肠派对》百亿好友关系实现毫秒级查询