UITextField SecureEntryText color changes

蓝咒 提交于 2019-12-10 10:10:31

问题


I have a subclass of UITextField where I set the text color to be white. I am using this subclass for an email field and a password field.

- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];

    self.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.layer.backgroundColor = [UIColor clearColor].CGColor;
    self.textColor = [UIColor whiteColor];
    [self setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
    ......
    ......

The password field has secureTextEntry set to YES, and when I first type in it the color is white as expected. Then, if I click the clear button, focus on the email field and then focus back on the password field and begin typing, the text is now black.

I'm not sure why it lost the color I set in my drawRect override. If I try the same steps with the email field it stays white no matter how many times I clear and unfocus/refocus the field.

I'm guessing this has to do with the secure text entry. Any help in this area will be much appreciated. Thanks!

来源:https://stackoverflow.com/questions/18991149/uitextfield-secureentrytext-color-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!