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];
```

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

我们可以在UIAlertController添加一个密码输入框,并设定文本输入框的颜色。
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.backgroundColor = [UIColor redColor];
textField.secureTextEntry = YES;
}];

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];

网友评论