3

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!

Adam Langsner
  • 1,276
  • 1
  • 15
  • 23
  • 4
    I've experienced a similar issue (that's why I arrived at this question), but in my case, it involves a normal text field. I set its text color in [textField:shouldChangeCharactersInRange:replacementString:] as a part of my data validation, and it reverts to its normal color (gray in my case) after it finishes editing. What I know is that it seems to be an iOS 7 bug. – Kenn Cal Nov 29 '13 at 06:07
  • Thank goodness you guys posted this! I thought I was going nuts! Yes, the second field "reverts" to the "other" color for no real reason, when you click off the field. It's an incredibly strange bug! it's like Apple memorises the "previous color" or some such and goes back to that - it's so freaky. Thanks again! – Fattie Dec 05 '13 at 21:14
  • Workaround: for confirmPassword, also connect the "Editing Did End" action to that method. Note that this very old question may now be irrelevant. – Fattie Apr 21 '16 at 12:04

0 Answers0