UIAlertController(IOS8.0)

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](http://upload-images.jianshu.io/upload_images/1709371-80075ff701c4c0e8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

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

![屏幕快照 2016-03-08 20.02.50.png](http://upload-images.jianshu.io/upload_images/1709371-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](http://upload-images.jianshu.io/upload_images/1709371-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](http://upload-images.jianshu.io/upload_images/1709371-980228fe41adb6a8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

你可能感兴趣的:(UIAlertController(IOS8.0))