github demo地址 如果觉得好用请给star鼓励 谢谢项目介绍
这是一款简约系统风格的弹窗,开发者可通过一句代码创建并弹出。
开发者可以选择通过代理的方式或者block的方式来监听按钮的点击事件。
开发者可通过settingHandler设置弹窗的背景颜色、字体颜色、字体以及分割线的颜色以满足不同风格的app的需求
更加详尽的使用情况请下载demo
使用说明安装将demo中的SLAlertView文件夹拖入项目
导入头文件
#import 'SLAlertView.h'#p#分页标题#e#
在需要弹窗的地方调用接口
1> 创建并弹出使用代理监听点击事件的默认的alert / actionSheet
2> 创建并弹出使用block监听点击事件的默认的alert / actionSheet
// 通过block回调方式创建alert [SLAlertView alertViewWithTitle:@'title' message:@'message' preferredStyle:SLAlertViewStyleAlert cancelButtonTitle:@'cancel' otherButtonTitles:@[@'other'] clickHandler:^(SLAlertView * _Nonnull alertView, NSInteger buttonIndex, NSString * _Nullable buttonTitle) { NSLog(@'block %ld-%@',buttonIndex,buttonTitle); }]; // 通过block回调方式创建action sheet [SLAlertView alertViewWithTitle:@'actionSheet' message:@'sheet_default' preferredStyle:SLAlertViewStyleActionSheet cancelButtonTitle:@'cancel' otherButtonTitles:@[@'other1',@'other2',@'other3'] clickHandler:^(SLAlertView * _Nonnull alertView, NSInteger buttonIndex, NSString * _Nullable buttonTitle) { NSLog(@'block sheet_default %ld-%@',buttonIndex,buttonTitle); }];3> 自定义的情况(以actionSheet为例,开题报告,开题报告,alert用法完全一样)
[SLAlertView alertViewWithTitle:@'title' message:@'message' preferredStyle:SLAlertViewStyleActionSheet cancelButtonTitle:@'cancel' otherButtonTitles:@[@'other1',@'other2'] settingHandler:^(SLAlertView * _Nonnull alertView) { alertView.titleBackgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0]; alertView.messageBackgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0]; alertView.otherBackgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0]; alertView.cancelBackgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0]; alertView.titleColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0]; alertView.messageColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0]; alertView.otherTitleColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0]; alertView.cancelTitleColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0]; alertView.separatorColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0]; alertView.titleFont = [UIFont fontWithName:@'AmericanTypewriter-Bold' size:16]; alertView.messageFont = [UIFont fontWithName:@'AmericanTypewriter' size:16]; alertView.otherTitleFont = [UIFont fontWithName:@'DBLCDTempBlack' size:16]; alertView.cancelTitleFont = [UIFont fontWithName:@'AmericanTypewriter-Bold' size:16]; } clickHandler:^(SLAlertView * _Nonnull alertView, NSInteger buttonIndex, NSString * _Nullable buttonTitle) { NSLog(@'block sheet_customBackgroundColor %ld-%@',buttonIndex,buttonTitle); }]; #p#分页标题#e#4> 代理方法。遵守协议 <SLAlertViewProtocol>
- (void)actionSheet:(SLActionSheet *)actionSheet didSelectedButtonWithButtonIndex:(NSInteger)index buttonTitle:(NSString *)buttonTitle { NSLog(@'actionSheet:didSelectedButtonWithButtonIndex:%ld buttonTitle:%@',index,buttonTitle); } - (void)alertView:(SLAlert *)alertView didSelectedButtonWithButtonIndex:(NSInteger)index buttonTitle:(NSString *)buttonTitle { NSLog(@'alertView:didSelectedButtonWithButtonIndex:%ld buttonTitle:%@',index,buttonTitle); }转载请注明出处,好用请github star。谢谢!
github地址:https://github.com/SongLazy/SLAlertView