When I'm in Safari in iOS, and I hit a form that requires I enter name and address, I get shortcuts in the keyboard area. For example, here is the keyboard when the focus is in a first name field. I can tap "Robert" instead of typing a name.
A similar thing happens for fields for last name, phone, email, zip code.
Can I get a similar thing in a native iOS app, in a UITextField
? Is there a way to mark a field so that the keyboard will offer these shortcut suggestions?
You can turn on or off it by set autocorrectionType
of UITextField
. Default value of autocorrectionType
is UITextAutocorrectionTypeDefault
. It means you don't need to do anything, by default it will be showed.
UITextAutocorrectionTypeYes; // Turn on
UITextAutocorrectionTypeDefault; // Turn on
UITextAutocorrectionTypeNo; // Turn off
But beside of set autocorrectionType
value, you need to make sure Predictive
in Keyboards Setting
of device is turned on. If Predictive
is turned off, suggestion won't be displayed even you changed autocorrectionType
to UITextAutocorrectionTypeYes
.
UPDATE
You can change textContentType
to choose with type of suggestion will be shown. Suggestions are from the Contacts
. For example, you want phone suggestion
textField.textContentType = UITextContentTypeTelephoneNumber;
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