程序员首页投稿(暂停使用,暂停投稿)自己尝试等装一下

UIAlertController 对话框

2016-06-25  本文已影响223人  蛊毒_
对话框的简单使用
创建一个UIAlertController对象
+ (instancetype)alertControllerWithTitle:(NSString *)title message:
(NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle
  UIAlertController *alert = [UIAlertController alertControllerWithTitle:
@"标题" message:@"内容" preferredStyle:UIAlertControllerStyleAlert];

创建两个UIAlertAction对象(相当于对话框下面的按钮)
+ (instancetype)actionWithTitle:(nullable NSString *)
 style:(UIAlertActionStyle) handler:^(UIAlertAction * _Nonnull action)handler
UIAlertAction *action = [UIAlertAction actionWithTitle:@"NO" 

style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        
        
    }];
    
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
    }];
    
    UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"测试" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
        
    }];
把创建的UIAlertAction对象添加到alert上
    [alert addAction:action];
    [alert addAction:action2];
    [alert addAction:action3];
模态推入对话框
[self presentViewController:alert animated:YES completion:^{
        
    }];
风格为UIAlertControllerStyleAlert时
QQ20160625-0.png QQ20160625-1.png
更改alert的风格 把风格改为UIAlertControllerStyleActionSheet
QQ20160625-2.png QQ20160625-3.png
上一篇 下一篇

猜你喜欢

热点阅读