Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size of bullets in UITextField with secureTextEntry changes size as focus switches when using custom font

Tags:

I have a UITextField that is using the Museo Sans Rounded 300 font. Everything works fine for normal UITextFields, but when you set the secureTextEntry = YES, then there's this disconcerting change to the size of the bullets as the UITextField gets and loses focus (i.e. becomes, and relinquishes, being the first responder).

When the UITextField has focus, the bullets appear to be using the custom font, but once it loses focus they change to being these much bigger (standard size) bullets.

like image 294
Mick Byrne Avatar asked Dec 18 '13 03:12

Mick Byrne


2 Answers

So, the only way I found to combat this was to use the textFieldDidBeginEditing and textFieldDidEndEditing delegate methods, keep track of what was entered in the text field, replace it with a mask of bullets, and disable secureTextEntry. So, when they leave the field, they’re actually just seeing the right number of bullets, rather than their secured text. It’s hacky and messy, but it’ll do for me, perhaps for you, too.

like image 163
Luke Avatar answered Oct 02 '22 08:10

Luke


I found an easy solution an it works quite good. Basically you have to change the font to a custom font when you set secureTextEntry to yes.

- (void)textFieldDidBeginEditing:(UITextField *)textField{

    if([textField.text isEqual:@"Password"]){
        textField.text = @"";
        textField.font = [UIFont fontWithName:@"Helvetica" size:14.5];
        textField.secureTextEntry = YES;
    }
}

- (void)textFieldDidEndEditing:(UITextField *)textField{

    if([textField.text isEqual:@""]){
        textField.text = @"Password";
        textField.secureTextEntry = NO;
        textField.font = [UIFont fontWithName:@"YourFont" size:14.5];
    }
}
like image 40
Javier Peigneux Avatar answered Oct 02 '22 09:10

Javier Peigneux