35

I faced with strange overlay on UITextField. I'm using field of type textContentType = .password and isSecureTextEntry = true. I have also eye button to unhide password characters with changing isSecureTextEntry = false.

When I do that my password characters are visible, but when I type at least one new character Strong password overlay appears and it's no way to hide it.

What is that and how to prevent to show it?

strong password overlay

// EDIT:

I've made extension to disable AutoFill and it's works:

extension UITextField {
    func disableAutoFill() {
        if #available(iOS 12, *) {
            textContentType = .oneTimeCode
        } else {
            textContentType = .init(rawValue: "")
        }
    }
}
MarcinR
  • 786
  • 1
  • 6
  • 16
  • 1
    I suppose this is one of Autofill features. I found same view on this web page: https://medium.com/developerinsider/ios12-password-autofill-automatic-strong-password-and-security-code-autofill-6e7db8da1810 – MarcinR Nov 20 '19 at 10:33
  • 1
    I think this is because of password autofill feature of iOS please try below code to get rid of it `if #available(iOS 12, *) { // iOS 12 & 13: Not the best solution, but it works. passwordTextField.textContentType = .oneTimeCode } else { // iOS 11: Disables the autofill accessory view. // For more information see the explanation below. emailTextField.textContentType = .init(rawValue: "") passwordTextField.textContentType = .init(rawValue: "") }` – Dixit Rathod Nov 20 '19 at 10:50
  • User would be able to cancel autofill, please can you test again, there would be a way for the user of the app to cancel autofill and manually fill it. – user1046037 Nov 20 '19 at 11:29
  • 1
    this is not working for me iphone 6s ios 13.5 – Sandeep Maurya Jul 02 '20 at 14:12
  • But this will stop autofill to work. For me I just want to avoid that yellow 'strong password' overlay. – Waqas Sep 15 '21 at 10:16

3 Answers3

11

Found the only solution for this problem.

textField.textContentType = .oneTimeCode

Otherwise iOS 12 uses PasswordAutofill for any secure field (textField.isSecureTextEntry = true).

This solution is from apple developer forum Yuri Petukhov' answer.

DarkHorse
  • 339
  • 4
  • 16
  • 2
    This just turns the field into a one-time-code field. Like a 6 digit code texted to the user. So yes.. This does fix it visually. But it's not really a password field anymore as far as auto fill is concerned. – joshuakcockrell Jul 26 '22 at 19:23
0

The other answers cause the text to be revealed to the user, which isn't ideal IMO.

To solve this:

Set the content type of the password field to: .oneTimePad, set secure text entry on the field to: false, and then add following (or whatever flavor works for you):

func textFieldDidBeginEditing(_ textField: UITextField) { 
    if(textField == self.passwordTextField) { self.passwordTextField.isSecureTextEntry = true } }

Side Note - I tried to put that ^ change in the viewWillAppear, but the ugly yellow box still shows up.

This was the only way I found to keep the text secured/hidden initially ( you can then toggle it with a show/hide button if you want and the autocomplete nonsense from Apple doesn't come back)

Joel
  • 423
  • 1
  • 6
  • 14
0

Credit Christian Diaz for the answer: This seems to be a bug with using secure text field on iOS simulators with version 14.0 and up. I would suggest using the simulator with version 13.7, the one right before 14.0. If you don't see the option to choose devices with 13.7, click on:

Xcode -> Preferences -> Components -> iOS 13.7 Simulator

This will install iOS 13.7 simulators for devices before the iPhone 12.

Just make sure you see 13.7 on your simulator's top bar.

Eli Gooch
  • 100
  • 1
  • 11