Change UIFont in secure UITextField strange behaviour in iOS7

前端 未结 5 1724
情书的邮戳
情书的邮戳 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 20:54

    Toggling secure/insecure state with a custom font: to show 'secure' text (blob characters), a font containing the blob character is set by iOS. This is the font you're later seeing render text when you switch to insecure mode.

    Though the textfield keeps your assigned custom font, the field's content is an attributed string which references the blob-containing font.

    The simple solution: write to the attributed string field, and your correct, custom font is re-applied.

    To turn off secure entry & keep a custom font:

    passwordTextField.secureTextEntry = false
    
    // We have to remove iOS' secure font by setting attributedText.
    let pwd = passwordTextField.text!
    passwordTextField.attributedText = NSAttributedString(string: pwd)
    

提交回复
热议问题