Change UIFont in secure UITextField strange behaviour in iOS7

前端 未结 5 1719
情书的邮戳
情书的邮戳 2020-12-08 20:10

I create a simple project: https://github.com/edzio27/textFieldExample.git

where I add two UITextFields, one with login and second one with secure passw

5条回答
  •  盖世英雄少女心
    2020-12-08 21:03

    Set your delegate of your TextField and add this;

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
        if (!textField.secureTextEntry) {
            return YES;
        }
    
        textField.text = [textField.text stringByReplacingCharactersInRange:range withString:string];
    
        if (textField.text.length > 0) {
            textField.font = [UIFont systemFontOfSize:18.0f];
        } else {
            textField.font = [UIFont fontWithName:@"YourFont" size:18.0f];
        }
    
        return NO;
    }
    

提交回复
热议问题