gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 12:58:12 25 4
gpt4 key购买 nike

我尝试在 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];
}

但结果是:

enter image description here

有谁知道怎么办?谢谢。

最佳答案

这有点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];

}];

关于uitextfield - 如何更改 UIAlertController 的文本框边框颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27311404/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com