為UITextFields添加單詞補全:AutocompleteField
AutocompleteField讓你能夠為你的UITextFields添加單詞補全。
Autocomplete, or word completion, is a feature in which an application predicts the rest of a word a user is typing.
How it works
Installation
Manual installation
ImportAutocompleteField.swiftinto your project.
CocoaPods
platform :ios, '8.0' pod "AutocompleteField", "~> 1.1"
Usage
The easiest way is to add aUITextFieldin your Storyboard, and then giving it theAutocompleteFieldsubclass. You can use the property editor to change both the padding and the completion color of the textfield.
If you want to add a field using code, there's a custom init method you can use:
import AutocompleteField let textField = AutocompleteField(frame: CGRectMake(10, 10, 200, 40), suggestions: ["Abraham", "George", "Franklin"]) view.addSubview(textField)
Customization
AutocompleteField is a subclass of UITextField, so you can modify it in the same way you normally would, without any restrictions. The new properties you can set are:
Property | Type | Description |
---|---|---|
padding | CGFloat | Left/right padding. |
completionColor | UIColor | The color of the suggestion. Defaults to the default placeholder color. |
suggestion | String | The current suggestion shown. Can be used to force a suggestion. |
suggestions | [String] | Array of suggestions. |
autocompleteType | AutocompleteType | The type of autocomplete that should be used. .Word will only hint the the next word in the suggestion and .Sentence will show all words. |
pixelCorrection | CGFloat | Move the suggestion label up or down. Sometimes there's a small difference, and this can be used to fix it. |
Demo
Check out the Example project.
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!