首页 > 移动平台 > 详细

ios8 UIAlertController

时间:2014-09-18 13:04:13      阅读:238      评论:0      收藏:0      [点我收藏+]

ios8 上面,用UIAlertController将UIAlertView和UIActionSheet合二为一了。 

(1)创建普通alert

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title  message:message  preferredStyle:UIAlertControllerStyleAlert];
    
    // Create the actions.
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle  style:UIAlertActionStyleCancel  handler:^(UIAlertAction *action) {
        NSLog(@"The \"Okay/Cancel\" alert‘s cancel action occured.");
    }];
    
    UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle  style:UIAlertActionStyleDefault  handler:^(UIAlertAction *action) {
        NSLog(@"The \"Okay/Cancel\" alert‘s other action occured.");
    }];
    
    // Add the actions.
    [alertController addAction:cancelAction];
    [alertController addAction:otherAction];
    
    [self presentViewController:alertController animated:YES completion:nil];

如果UIAlertAction *otherAction这种otherAction多几个的话,它会自动排列成一列。

(2)带有输入框的alert

如果需要在 alertview上面添加输入框等,如下:
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        // 可以在这里对textfield进行定制,例如改变背景色
        textField.backgroundColor = [UIColor orangeColor];
    }];

ios8 UIAlertController

原文:http://www.cnblogs.com/417460188dy/p/3978824.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!