gpt4 book ai didi

ios - 带有安全选项的 UITextField 的 NSAttributedString 背景颜色

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:08:42 25 4
gpt4 key购买 nike

当用户指定错误时,我希望登录名/密码字段有红色背景。

NSAttributedString *loginString = [[NSAttributedString alloc] initWithString:_loginField.text attributes:@{NSBackgroundColorAttributeName : [UIColor redColor]}];

此代码非常适合登录,但对于带有 Secure 选项(密码)的 UITextField,它根本不起作用。iOS 是否有任何标准方法可以使文本字段星号下的背景变红?

最佳答案

这对我来说效果很好。我创建了 2 个 UITextField,1 个常规的和 1 个安全的,还有一个按钮来获取它们的内容并使它们的背景完全按照你上面写的那样设置为红色:

NSAttributedString *loginString = [[NSAttributedString alloc] initWithString:usernameField.text attributes:@{NSBackgroundColorAttributeName : [UIColor redColor]}];
[usernameField setAttributedText:loginString];

// field set as secure in xib
NSAttributedString *pwString = [[NSAttributedString alloc] initWithString:passwordField.text attributes:@{NSBackgroundColorAttributeName : [UIColor redColor]}];
[passwordField setAttributedText:pwString];

之前:

enter image description here

之后:

enter image description here

关于ios - 带有安全选项的 UITextField 的 NSAttributedString 背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20839251/

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