ios警告与提示对话框

  进行iOS开发过程中,不可避免的使用到各种提醒,来提醒用户当前操作,或是为了警告,或是为了数据缓冲。

  本文介绍了使用 UIAlertController和UIAlertAction两个类,完成三种状态的提醒。

这里首先使用UIAlertController创建一个提示对话框,按照工厂方法即可快速创建,参数UIAlertControllerStyle只有一种样式:UIAlertControllerStyleAlert。

填写完提示的标题和内容后,就可以使用UIAlertAction创建一个具体的按钮行为了。参数UIAlertActionStyle有三种样式, UIAlertActionStyleDefault(普通)、UIAlertActionStyleCancel(取消)、UIAlertActionStyleDestructive(警告(破坏性的))。默认状态是正常蓝色字体,取消状态时字体加粗,而警告状态字体则会变为红色。当只添加一个行为对象时,行为对象会显示在UIAlertController对象的下面,添加2个时,并排显示,添加3个及以上者,按列显示。

  你可以很方便的在任意一个事件响应函数中,添加以下代码,并在块语句中添加当用户选择相应的选项时执行的语句。

 

    //使用UIAlertController创建一个提示对话框,只有标题和信息
    //UIAlertControllerStyle只有一种样式:UIAlertControllerStyleAlert
    
    //使用UIAlertAcion创建具体的行为,同时添加三个则按列显示
    //UIAlertActionStyle有三种样式,普通、取消、警告(破坏性的)
    //UIAlertActionStyleDefault、UIAlertActionStyleCancel(字体加粗显示)、UIAlertActionStyleDestructive(字体红色显示)
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"标题" message:@"messagebox" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    }];
    UIAlertAction *action2= [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
    }];
    UIAlertAction *action3= [UIAlertAction actionWithTitle:@"警告" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
    }];
    
    [alert addAction:action1];
    [alert addAction:action2];
    [alert addAction:action3];
    [self presentViewController:alert animated:YES completion:^{
    }];

 

  

    

 

    

 

转载于:https://www.cnblogs.com/bravely/p/4716155.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值