In one of our iOS / iPhone Apps we need to display the user's configured email addresses as suggestions during the registration process. There are several apps that display email addresses as fixed buttons within the input accessory view of the keyboard. The Yelp app for instance (iPhone 8 with iOS 13.4)

I could not figure out how enable this functionality with built-in means. I tried to set textContentType, keyboardType and autocorrectionType to the correct values as described in other stack overflow articles I could find about this topic.
This is my code
override func viewDidLoad() {
super.viewDidLoad()
let email = UITextField(frame: CGRect(x: 10, y: 60, width: 300, height: 40))
email.placeholder = "Enter email address here"
email.font = UIFont.systemFont(ofSize: 15)
email.borderStyle = UITextField.BorderStyle.roundedRect
email.clearButtonMode = UITextField.ViewMode.whileEditing
email.contentVerticalAlignment = UIControl.ContentVerticalAlignment.center
email.returnKeyType = .continue
email.keyboardType = .emailAddress
email.textContentType = .emailAddress
email.autocorrectionType = .yes
email.autocapitalizationType = .none
view.addSubview(email)
}
And this is how it looks like on the same iPhone 8 with iOS 13.4 as I was running the Yelp App on:

No email address suggestions.
The curious thing is that the same App running on my iPad shows suggestions but in a different way:

How can I display the user's email addresses in the same way as Yelp does it? Is there a special UITextField view I have to use or is there another way to get the email addresses and display them in a custom text accessory view?
Thanks for your help!
I solved this problem giving UITextField with accessibilityLabel = "Registration" instead of rename view controller.
After some research of other Apps that have the correct behavior I found a solution for the problem above.
Apple does a little bit of magic in the background, called "Heuristic" but Apple does not describe it.
Our problem was, that there was only a UITextField asking for an email address and there was no context.
This needs to be done:
Our solution was to hide the password text field below the email text field. The password text field must be at least one point below the email text field to make it editable. We just put a view between email and password to hide it.
After editing or selecting the email address, we animated moved the password text field below the email text field.
This one started to melt my brain but at least we found a solution that worked for us.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With