iOS autocomplete feature

2019-03-16 03:59发布

问题:

What most people mean by autocomplete is that the app has a textview/searchbar/whatever which accepts user input. Attached to this component is a tableview which keeps updating based on the user input. This is a well researched topic and is now relatively easy to implement thanks to the UISearchDisplay controller.

Now here is what I want. When the user is typing in some text in the UISearchBar, there will be no searchdisplaycontroller. Instead, I want the app to do something like Google Instant on desktops. That is, if I type "Goog", the searchbar should show Goog*le. So the suggestion "le" should be in a lighter font than the rest of the user input string Google. So I don't want an auto-suggest feature, I want an autocomplete feature.

Any ideas on how I can do this?

Thanks!

回答1:

I haven't tried it but here's a control that appears to do what you're asking for:

http://cocoacontrols.com/platforms/ios/controls/doautocompletetextfield



回答2:

Alternatively, you can use this UITextField subclass (inspired by DOAutocompleteTextField):

https://github.com/hoteltonight/HTAutocompleteTextField

It's got a few more features and is actively developed. The example shows you how to use an array as the data source for the autosuggest text.