Labels or autocomplete for contact information in UITextFields

When I'm in Safari on iOS and I hit a form where I need to enter a name and address, I get shortcuts in the keyboard area. For example, here's the keyboard when the focus is on the name field. I can press "Robert" instead of entering a name.

enter image description here

The same thing happens for the fields for last name, phone number, email, zip code.

Can I get this in a native iOS app, in UITextField

? Is there a way to mark a box so that the keyboard will suggest these shortcuts?

+3


source to share


1 answer


You can turn it on or off by setting autocorrectionType

to UITextField

. The default autocorrectionType

is UITextAutocorrectionTypeDefault

. This means you don't need to do anything, it will be shown by default.

UITextAutocorrectionTypeYes; // Enable

UITextAutocorrectionTypeDefault; // Enable

UITextAutocorrectionTypeNo; // Disable

But in addition to the value set autocorrectionType

you need to make sure Predictive

to Keyboards Setting

turn on the device. If Predictive

disabled, the offer will not be displayed even if you changed autocorrectionType

to UITextAutocorrectionTypeYes

.



UPDATE

You can change textContentType

to select the type of hint. Offers from Contacts

. For example, you want a phone offer

textField.textContentType = UITextContentTypeTelephoneNumber;

      

+1


source







All Articles