TSMessagesNW 0.9.15

TSMessagesNW 0.9.15

测试测试
Lang语言 Obj-CObjective C
许可 MIT
发布最后发布2016年2月

CaoJun 维护。



  • 作者:
  • Cao Jun

TSMessages-NoWarning

查找 [pull-request]

这个库提供了一个易于使用的类,可以在屏幕顶部显示小的通知视图。(类似于 Tweetbot)。

通知从屏幕顶部移动到导航条下方,并保持几秒钟,具体时间取决于显示文本的长度。要在时间用尽前关闭通知,用户可以将其向上滑动或直接点击。

已经为您设置好了 4 种不同的类型:成功、错误、警告、消息(查看截图)

添加不同设计的通知类型非常简单。将新类型添加到 notificationType 枚举中,将所需的设计属性添加到配置文件中,并在 TSMessagesView.m 中的 switch 案例中设置主题名称(在配置文件和图片中使用)。

查看示例项目以了解如何使用此库。 由于示例项目使用 Cocoapods,因此您必须打开工作区,而不是项目文件。

在 Twitter 上联系开发者: KrauseFx(Felix Krause)

安装

手动

将 TSMessageView 和 TSMessage 文件复制到您的项目中。同时复制 TSMessagesDesignDefault.json。

使用

要显示通知,请使用以下代码

    [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"];

您可以为显示通知定义一个默认视图控制器

   [TSMessage setDefaultViewController:myNavController];

您可以为显示通知定义一个默认视图控制器

   [TSMessage setDelegate:self];

   ...

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

您可以在显示之前自定义一个消息视图,如设置透明度值或添加自定义子视图

   [TSMessage setDelegate:self];

   ...

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

您可以使用UIAppearance自定义消息视图元素

#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;
}

在创建新通知时可以设置以下属性

  • viewController:显示通知的视图控制器。这可能是导航控制器。
  • title:通知视图的标题
  • subtitle:显示在标题下方的文本(可选)
  • image:用于替代默认图标的自定义图标图像(可选)
  • type:通知类型(消息、警告、错误、成功)
  • duration:通知应显示的持续时间
  • callback:当用户通过点击或将其向上滑动以关闭消息时执行的代码块。

除标题和通知类型外,列出的所有值都是可选的

如果您不需要详细的描述(标题下的文本),则无需设置。通知将自动调整大小。

屏幕截图

iOS 7 设计

iOS 7 Error

iOS 7 Message

iOS 6 设计

Warning

Success

Error

Message

许可证

TSMessages 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。

最近更改

可以在本存储库的 发行版部分 找到。