ISMessages
这是一个简单的扩展,用于从设备的顶部或底部呈现全局通知。
要求
- 需要iOS 8.2或更高版本
- 需要自动引用计数(ARC)
特性
- 简单易用的操作
- 从应用中的任何地方调用
安装
CocoaPods
要使用 CocoaPods 安装 ISMessages,请将其整合到现有的 Podfile 中,或者创建一个新的 Podfile
target 'MyApp' do
pod 'ISMessages'
end
然后运行 pod install
。
手册
将 ISMessages 文件夹添加到项目中
用法
#import <ISMessages/ISMessages.h>
显示通知
所有消息都可以通过静态方法调用简单地显示,无需自定义和回调操作
[ISMessages showCardAlertWithTitle:@"This is your title!"
message:@"This is your message!"
duration:3.f
hideOnSwipe:YES
hideOnTap:YES
alertType:ISAlertTypeSuccess
alertPosition:ISAlertPositionTop
didHide:^(BOOL finished) {
NSLog(@"Alert did hide.");
}];
具有自定义和回调操作的消息
ISMessages* alert = [ISMessages cardAlertWithTitle:@"This is custom alert with callback"
message:@"This is your message!!"
iconImage:[UIImage imageNamed:@"Icon-40"]
duration:3.f
hideOnSwipe:YES
hideOnTap:YES
alertType:ISAlertTypeCustom
alertPosition:ISAlertPositionTop];
alert.titleLabelFont = [UIFont boldSystemFontOfSize:15.f];
alert.titleLabelTextColor = [UIColor blackColor];
alert.messageLabelFont = [UIFont italicSystemFontOfSize:13.f];
alert.messageLabelTextColor = [UIColor whiteColor];
alert.alertViewBackgroundColor = [UIColor colorWithRed:96.f/255.f
green:184.f/255.f
blue:237.f/255.f
alpha:1.f];
[alert show:^{
NSLog(@"Callback is working!");
} didHide:^(BOOL finished) {
NSLog(@"Custom alert without image did hide.");
}];
消息可以显示在应用程序的任何位置,甚至与 UI 无关。
隐藏消息
通知将在指定时长后自动隐藏,或者可以使用静态方法进行隐藏
[ISMessages hideAlertAnimated:YES];
您还可以直接点击/滑动 {on} 消息以隐藏它。
作者
Ilya Inyushin