高度自定义系统UIActionSheet与UIAlertView视图

高度自定义简单易用的UIActionSheet与UIAlertView视图

一、模仿系统的UIActionSheet, 封装了一个多样式的ActionSheetView, 用法简单,导入头文件, OKActionSheetView.h使用;

使用pod导入方法: pod 'OKAlertContrActionSheet', '~> 0.0.3'

1. 顶部下拉弹框样式:

顶部下拉弹框样式

代码用法:

NSArray *btnImgNameArr = @[@"commonQut-nor",@"commonQut-nor",@"commonQut-nor",@"commonQut-nor",@"commonQut-nor",@"commonQut-nor",@"commonQut-nor"];

NSArray *btnTitleArr = @[@"常见问题1",@"常见问题2",@"常见问题3",@"常见问题4",@"常见问题5",@"常见问题6",@"常见问题7"];

[OKActionSheetView actionSheetByTopSquare:^(NSInteger buttonIndex) {
    ShowAlertToast([NSString stringWithFormat:@"点击了第%zd行",buttonIndex]);
        
} cancelButtonBlock:^{
    ShowAlertToast(@"点击取消按钮");
        
} superView:self.view position:CGPointMake(0, 64) buttonTitleArr:btnTitleArr buttonImageArr:btnImgNameArr];

2. 底部上拉弹框直角样式:

底部上拉弹框直角样式

代码用法:

NSString *title = @"人在临死的时候最明白一切都是过眼云烟";

NSArray *otherTitleArr = @[@"按钮1",@"按钮2",@"按钮3",@"按钮4",@"按钮5",@"按钮6",@"按钮7",@"按钮8"];

[OKActionSheetView actionSheetByBottomSquare:^(NSInteger buttonIndex) {
    ShowAlertToast([NSString stringWithFormat:@"点击了第%zd个按钮",buttonIndex]);

} cancelButtonBlock:^{
    ShowAlertToast(@"点击取消按钮");
        
} WithTitle:title cancelButtonTitle:@"取消" otherButtonTitleArr:otherTitleArr];

3. 底部上拉弹框圆角样式:

底部上拉弹框圆角样式

代码用法:

NSString *title = @"生命是个过程,死亡只是必然的结果,但轨迹是自己的色彩和温度,既然不可避免,那么就更无所畏惧。";

NSArray *otherTitleArr = @[@"按钮1",@"按钮2",@"按钮3",@"按钮4",@"按钮5",@"按钮6",@"按钮7",@"按钮8"];

[OKActionSheetView actionSheetByBottomCornerRadius:^(NSInteger buttonIndex) {
    ShowAlertToast([NSString stringWithFormat:@"点击了第%zd行",buttonIndex]);

} cancelButtonBlock:^ {
    ShowAlertToast(@"点击取消按钮");
        
} WithTitle:title cancelButtonTitle:@"取消" otherButtonTitleArr:otherTitleArr];

二、封装系统提示框, 兼容iOS9以下的UiAlertView, 和iOS9以上的UIAlertController;

1. 普通两个按钮弹框样式:

普通两个按钮弹框样式

代码用法:

NSString *tipStr = @"第2个弹框标题";
    
[OKAlertView alertWithCallBlock:^(NSInteger buttonIndex) {
    ShowAlertToast([NSString stringWithFormat:@"点击了第%zd个按钮",buttonIndex]);

} title:@"温馨提示" message:tipStr cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

2. 普通两个以上按钮弹框样式:

普通两个以上按钮弹框样式

代码用法:

NSString *titleStr = @"温馨提示";
NSString *msgStr = @"显示两个以上按钮";
    
NSMutableAttributedString *titleAttr = [[NSMutableAttributedString alloc] initWithString:titleStr];
[titleAttr setAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:22],NSForegroundColorAttributeName:[UIColor yellowColor]} range:NSMakeRange(0, 2)];
    
NSMutableAttributedString *msgAttr = [[NSMutableAttributedString alloc] initWithString:msgStr];
[msgAttr setAttributes:@{NSForegroundColorAttributeName:[UIColor cyanColor], NSFontAttributeName:[UIFont systemFontOfSize:30]} range:NSMakeRange(2, 2)];

NSMutableAttributedString *buttonTitleAttr = [[NSMutableAttributedString alloc] initWithString:@"确定测试一下"];
[buttonTitleAttr setAttributes:@{NSForegroundColorAttributeName:[UIColor redColor], NSFontAttributeName:[UIFont systemFontOfSize:30]} range:NSMakeRange(2, 2)];
    
[OKAlertView alertWithCallBlock:^(NSInteger buttonIndex) {
      ShowAlertToast([NSString stringWithFormat:@"点击了第%zd个按钮",buttonIndex]);

} title:titleAttr message:msgAttr cancelButtonTitle:@"取消" otherButtonTitles:@"确定1",buttonTitleAttr,@"确定3", nil];

3. 底部上拉弹框Item圆角弹框样式:

底部上拉弹框Item圆角弹框样式

代码用法:

NSArray *btnImgNameArr = @[@"commonQut-nor",@"commonQut-nor",......];
NSArray *btnTitleArr = @[@"常见问题1",@"常见问题2",...];

[OKActionSheetView actionSheetByBottomItemCornerRadius:^(NSInteger buttonIndex, id title) {
        ShowAlertToast(title);

} cancelButtonBlock:^{
        ShowAlertToast(@"点击取消按钮");

} sheetTitle:nil cancelButtonTitle:@"取消" buttonTitleArr:btnTitleArr buttonImageArr:btnImgNameArr];

4. 系统带输入弹框弹框样式:

系统带输入弹框弹框样式

代码用法:

[OKAlertView inputAlertWithTitle:@"请输入"
                         placeholder:@"输入弹框控件"
                         cancelTitle:@"取消"
                          otherTitle:@"确定"
                        keyboardType:UIKeyboardTypeDefault
                         buttonBlock:^(NSString *inputText) {
                             ShowAlertToast([NSString stringWithFormat:@"您输入了:\n%@",inputText]);
                         } cancelBlock:^{
                             ShowAlertToast(@"点击了取消按钮");
                         }];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,267评论 4 61
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,956评论 25 709
  • WebSocket-Swift Starscream的使用 WebSocket 是 HTML5 一种新的协议。它实...
    香橙柚子阅读 24,171评论 8 184
  • 有些坚强需要不断的磨滚翻打,熟视无睹。 当我今天已经是做兼职的第10天了,其中我埋怨过,指责过,但更多的就是无奈过...
    叶纸an阅读 188评论 0 0
  • 已经养成一种习惯了,一种深夜不眠的习惯,记不起了,这样的习惯是什么时候形成的。不知道从什么时候开始,我好像更加迷恋...
    笔名唐小鸭阅读 282评论 0 0