Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortcuts or autofill for contact info in UITextFields

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.

enter image description here

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?

like image 307
Rob N Avatar asked Jun 01 '17 16:06

Rob N


1 Answers

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;
like image 134
trungduc Avatar answered Oct 06 '22 00:10

trungduc