这是一个简单的扩展,用于从设备屏幕底部显示多个全局通知。
#import <EHPlainAlert/EHPlainAlert.h>
所有消息都可以通过静态方法调用来简单地显示
[EHPlainAlert showAlertWithTitle:@"Success" message:@"Something works!" type:ViewAlertSuccess];
可以在应用中的任何位置显示消息,甚至是与 UI 无关的位置。
[[NetHelper sharedInstance] postRequestWithURLString:URL data:data withSuccess:^(id responseObject) {
[EHPlainAlert showAlertWithTitle:@"Success" message:@"Data successfully uploaded" type:ViewAlertSuccess];
} failure:^(NSError *error)
{
[EHPlainAlert showError:error];
}];
为了简化错误处理,您可以使用以下方法:
- (void)someError:(NSError *)myError
{
[EHPlainAlert showError:error];
}
通知将在 4 秒后自动隐藏。
要更改默认延迟,请使用以下静态方法:[EHPlainAlert updateHidingDelay:2.5f];
您还可以只需轻触消息即可隐藏它。
您可以更改轻触通知时的默认行为
EHPlainAlert * ehAlert = [[EHPlainAlert alloc] initWithTitle:@"Hmm..." message:@"Tap for information" type:ViewAlertInfo];
ehAlert.action = ^{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://github.com/josshad/EHPlainAlert"]];
};
[ehAlert show];
更改一个警告的字体
EHPlainAlert * ehAlert = [[EHPlainAlert alloc] initWithTitle:@"Info" message:@"This is info message" type:ViewAlertInfo];
ehAlert.titleFont = [UIFont fontWithName:@"TrebuchetMS" size:15];
ehAlert.subTitleFont = [UIFont fontWithName:@"TrebuchetMS-Italic" size:12];
[ehAlert show];
更改警告类型字体
[EHPlainAlert updateTitleFont:[UIFont fontWithName:@"TrebuchetMS" size:18]];
[EHPlainAlert updateSubTitleFont:[UIFont fontWithName:@"TrebuchetMS" size:10]];
更改一个警告的背景颜色
EHPlainAlert * ehAlert = [[EHPlainAlert alloc] initWithTitle:@"Hmm..." message:@"Blue color alert" type:ViewAlertInfo];
ehAlert.messageColor = [UIColor blueColor];
[ehAlert show];
更改警告类型的颜色
[EHPlainAlert updateAlertColor:[UIColor colorWithWhite:0 alpha:0.5] forType:ViewAlertPanic];
[EHPlainAlert updateAlertPosition:ViewAlertPositionTop];
更改一个警告的图标
EHPlainAlert * ehAlert = [[EHPlainAlert alloc] initWithTitle:@"Hmm..." message:@"Blue color alert" type:ViewAlertInfo];
ehAlert.iconImage = image;
[ehAlert show];
更改警告类型的图标
[EHPlainAlert updateAlertIcon:image forType:ViewAlertInfo];
[EHPlainAlert updateNumberOfAlerts:4];
[EHPlainAlert updateHidingDelay:2.5f];
Danila Gusev