美文网首页
【iOS UI】UIAlertController

【iOS UI】UIAlertController

作者: XIAO_WEN | 来源:发表于2017-05-18 14:31 被阅读39次
    UIAlertController

    1、创建Button绑定alert方法

        self.btn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.btn.backgroundColor = [UIColor orangeColor];
        self.btn.frame = CGRectMake(100, 100, 200, 200);
        [self.btn setTitle:@"Alert" forState:UIControlStateNormal];
        [self.btn addTarget:self action:@selector(alert) forControlEvents:UIControlEventTouchDown];
        [self.view addSubview:self.btn];
    

    2、alert方法

    - (void)alert{
        
        //  初始化AlertController
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"AlertControllerTitle" message:@"AlertControllerMessage" preferredStyle:UIAlertControllerStyleAlert];
        
        //  UIAlertActionStyleDefault
        UIAlertAction *firstAction = [UIAlertAction actionWithTitle:@"1" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        //  UIAlertActionStyleCancel
        UIAlertAction *secondAction = [UIAlertAction actionWithTitle:@"2" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        //  UIAlertActionStyleDestructive
        UIAlertAction *thirdAction = [UIAlertAction actionWithTitle:@"3" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        //  添加action
        [alert addAction:firstAction];
        [alert addAction:secondAction];
        [alert addAction:thirdAction];
        
        //  显示
        [self presentViewController:alert animated:YES completion:nil];
        
    }
    

    3、UIAlertControllerStyle

        typedef NS_ENUM(NSInteger, UIAlertControllerStyle) {
        UIAlertControllerStyleActionSheet = 0,
        UIAlertControllerStyleAlert
        } NS_ENUM_AVAILABLE_IOS(8_0);
    

    UIAlertControllerStyleActionSheet

    UIAlertControllerStyleActionSheet

    UIAlertControllerStyleAlert

    UIAlertControllerStyleAlert

    4、UIAlertActionStyle

    typedef NS_ENUM(NSInteger, UIAlertActionStyle) {
        UIAlertActionStyleDefault = 0,
        UIAlertActionStyleCancel,
        UIAlertActionStyleDestructive
    } NS_ENUM_AVAILABLE_IOS(8_0);
    
    UIAlertActionStyle

    1.UIAlertActionStyleDefault 蓝色 细体
    2.UIAlertActionStyleCancel 蓝色 粗体
    3.UIAlertActionStyleDestructive 红色 细体

    相关文章

      网友评论

          本文标题:【iOS UI】UIAlertController

          本文链接:https://www.haomeiwen.com/subject/lussxxtx.html