Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 59 lines (43 sloc) 2.183 kb
01a6b67 @hezi First Commit
hezi authored
1 #DOAutocompleteTextField
2
3 DOAutocompleteTextField is a subclass of UITextField that provide the user with
4 autocompleted text, similar to the URL bar on major browsers and Google Suggest.
5
6 ![DOAutocompleteTextField Screenshot](https://github.com/doat/DOAutocompleteTextField/raw/master/screenshot.gif)
7
8 #Usage
9
10 Add DOAutocompleteTextField to your project, create an instance of it
11 as you would create a UITextField and set the delegate.
12
13 DOAutocompleteTextField *textField = [[DOAutocompleteTextField alloc] initWithFrame:CGRectMake(0,0,100,31)];
14 textField.delegate = self;
15
16 In your DOAutocompleteTextFieldDelegate provide the completions according to you own logic
17 or similar to the demo.
18
19 - (NSString *)textField:(DOAutocompleteTextField *)textField completionForPrefix:(NSString *)prefix
20 {
21 // This is a simple example of how to provide DOAutocomleteTextField with completions
22 NSArray *autocompleteArray = [NSArray arrayWithObjects:
23 @"thesaurus",
24 @"the weather channel",
25 @"DoAT",
26 @"Doctor Who",
27 @"Dachshunds are the best",
28 @"ccccombo breaker",
29 @"money",
30 @"Mona lisa",
31 @"Monalisa",
32 @"mcdonalds",
33 @"mc hammer",
34 @"long cat is looooooooooooooooooog",
35 nil];
36
37 for (NSString *string in autocompleteArray)
38 {
39 if([string hasPrefix:prefix])
40 {
41 return [string stringByReplacingCharactersInRange:[prefix rangeOfString:prefix] withString:@""];
42 }
43
44 }
45
46 return @"";
47 }
48
49 DOAutocompleteTextField draws the completion text immediatlly after user input.
50
51 #Known Issues
52
53 * Completion position is still a bit off.
54 * No way of detecting taps on autocomplete label.
55
56
57 ##Copyright
58 Copyright 2011 DoAT. All rights reserved. See LICENSE for more details.
Something went wrong with that request. Please try again.