如何更改UIAlertController的文本框边框颜色

mon*_*jer 7 uitextfield

我尝试在ios中使用UIActionController来显示文本字段,我想知道如何更改文本字段边框颜色.

我的代码是:

- (void)showChangePasswordAlertView
{
    UIAlertController *actionVC = [UIAlertController alertControllerWithTitle:@""
                                                                  message:@"Change your password."
                                                           preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK"
                                                 style:UIAlertActionStyleDefault
                                               handler:^(UIAlertAction *action) {
                                               }];
    [actionVC addAction:action];

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

    [actionVC addTextFieldWithConfigurationHandler:^(UITextField *textField) {
       textField.placeholder = @"old password";
       textField.borderStyle = UITextBorderStyleNone;
       textField.layer.borderColor = [UIColor redColor].CGColor;
       textField.layer.borderWidth = 1.0 ;
      textField.secureTextEntry = YES ;
    }];

    [actionVC addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"new password";
        textField.borderStyle = UITextBorderStyleNone;
        textField.secureTextEntry = YES ;
    }];

    [actionVC addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"confirm new password";
        textField.borderStyle = UITextBorderStyleNone;
        textField.secureTextEntry = YES ;
    }];

    [self presentViewController:actionVC animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)

但结果是:

在此输入图像描述

任何身体都知道该怎么办?谢谢.

Asa*_*saf 0

这有点 hacky,但它确实有效(在 iOS 8.3 上测试):

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert"
                                                               message:@"This is an alert."
                                                        preferredStyle:UIAlertControllerStyleAlert];

[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {

    textField.placeholder = @"This is my placeholder";
    [[textField superview] superview].backgroundColor = [UIColor redColor];

}];
Run Code Online (Sandbox Code Playgroud)