Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork23
ARAutocompleteTextView is a subclass of UITextView that automatically displays text suggestions in real-time. This is perfect for automatically suggesting the domain as a user types an email address, #hashtag or@alexruperez.
License
alexruperez/ARAutocompleteTextView
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
ARAutocompleteTextView is a subclass of UITextView that automatically displays text suggestions in real-time. This is perfect for automatically suggesting the domain as a user types an email address, #hashtag or @handle.
ARAutocompleteTextView.mARAutocompleteTextView.hARAutocompleteManager.mARAutocompleteManager.h
Create anARAutocompleteTextView instance exactly as as you wouldUITextView. You can do eith either programmitcally or in Interface Builder. Programmatically, this looks like:
ARAutocompleteTextView* textField = [[ARAutocompleteTextView alloc] initWithFrame:CGRectMake(0,0,100,31)];let textField = ARAutocompleteTextView(frame: CGRectMake(0, 0, 100, 31))The data source is the brains of the autocomplete logic. If you just want to autocomplete email addresses, #hashtags or @handles, useARAutocompleteManager from the example project as follows:
textField.autocompleteDataSource = [ARAutocompleteManager sharedManager];textField.autocompleteType = ARAutocompleteTypeEmail;textField.autocompleteDataSource = ARAutocompleteManager.sharedManager()textField.autocompleteType = ARAutocompleteType.MailARAutocompleteManager (included in the example project) provides email address autocompletion out of the box. It comes with a list of the top email domains. You may want to tailor this list of email domains to match your own customers, or you may want to write autocomplete logic for a different type of text view (in the demo, names of colors are autocompleted).
Alternatively, you may wish to create your own data source class and user theautocompleteType property to differentiate between textviews with different data types. AARAutocompleteTextView's data source must implement the following method, as part of theARAutocompleteDataSource protocol.
- (NSString *)textField:(ARAutocompleteTextView*)textField completionForPrefix:(NSString *)prefixYou may also set a defaultdataSource for all instances ofARAutocompleteTextView. In the example project, we use aARAutocompleteManager singleton:
[autocompleteTextOffset setDefaultAutocompleteDataSource:[ARAutocompleteManager sharedManager]];To adjust the position of the autocomplete label by a fixed amount, setautocompleteTextOffset:
textField.autocompleteTextOffset = CGPointMake(10.0, 10.0);For more dynamic positioning of the autocomplete label, subclassARAutocompleteTextView and override- (CGRect)autocompleteRectForBounds:(CGRect)bounds.
To adjust the properties (i.e.font,textColor) of the autocomplete label, do so via the `[AutocompleteTextField autocompleteLabel] property.
textField.autocompleteLabel.textColor = [UIColor grayColor];In addition to observing the standardUITextView notifications (i.e.UITextViewTextDidChangeNotification and friends), you can use[ARAutocompleteTextView autoCompleteTextFieldDelegate] to listen for certain events. This is particularly useful if you are collecting analytics.
- Use this in your apps whenever you can, particularly email addresses -- your users will appreciate it!
- Contributions are very welcome.
- Attribution is appreciated (let's spread the word!), but not mandatory.
Tweet the author @alexruperez, and check out alexruperez's blog:http://alexruperez.com
About
ARAutocompleteTextView is a subclass of UITextView that automatically displays text suggestions in real-time. This is perfect for automatically suggesting the domain as a user types an email address, #hashtag or@alexruperez.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.
