美文网首页
UIAlertController(IOS8.0)

UIAlertController(IOS8.0)

作者: _叫我小贱 | 来源:发表于2016-03-08 19:48 被阅读64次

UIAlertController取代了UIActionSheet和UIAlertView。
UIAlertView:

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert" message:@"This is message" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
   UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {}];
    
    
    [alert addAction:okAction];
    [alert addAction:cancelAction];
    [self presentViewController:alert animated:YES completion:nil];
    ```

![屏幕快照 2016-03-08 19.47.00.png](https://img.haomeiwen.com/i1709371/80075ff701c4c0e8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

如果再添加一个Action就会形成一下效果

![屏幕快照 2016-03-08 20.02.50.png](https://img.haomeiwen.com/i1709371/7b15612a78c78393.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

我们可以在UIAlertController添加一个密码输入框,并设定文本输入框的颜色。

[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {

    textField.backgroundColor = [UIColor redColor];
    textField.secureTextEntry = YES;
    
}];
![屏幕快照 2016-03-08 20.14.06.png](https://img.haomeiwen.com/i1709371/342d42bdbb75f847.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

UIActionSheet:

UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

}];

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    
}];

[alert addAction:cancelAction];
[alert addAction:okAction];
[self presentViewController:alert animated:YES completion:nil];

![屏幕快照 2016-03-08 20.30.47.png](https://img.haomeiwen.com/i1709371/980228fe41adb6a8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

相关文章

网友评论

      本文标题:UIAlertController(IOS8.0)

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