Skip to content

Commit

Permalink
Merge pull request #79 from VUID/master
Browse files Browse the repository at this point in the history
Added token initialization functions and ability to limit number of tokens to be entered
  • Loading branch information
thermogl committed Jan 29, 2014
2 parents 7e51213 + d52d9b5 commit 76ef9d4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
5 changes: 4 additions & 1 deletion TITokenField.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,14 @@ typedef enum {
@property (nonatomic, assign) BOOL resultsModeEnabled;
@property (nonatomic, assign) BOOL removesTokensOnEndEditing;
@property (nonatomic, readonly) int numberOfLines;
@property (nonatomic) int tokenLimit;
@property (nonatomic, strong) NSCharacterSet * tokenizingCharacters;

- (void)addToken:(TIToken *)title;
- (TIToken *)addTokenWithTitle:(NSString *)title;
- (TIToken *)addTokenWithTitle:(NSString *)title representedObject:(id)object;
- (void)addTokensWithTitleList:(NSString *)titleList;
- (void)addTokensWithTitleArray:(NSArray *)titleArray;
- (void)removeToken:(TIToken *)token;
- (void)removeAllTokens;

Expand Down Expand Up @@ -139,4 +142,4 @@ typedef enum {
+ (UIColor *)redTintColor;
+ (UIColor *)greenTintColor;

@end
@end
25 changes: 22 additions & 3 deletions TITokenField.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ - (void)setup {
_showAlreadyTokenized = NO;
_searchSubtitles = YES;
_forcePickSearchResult = NO;
_shouldSortResults = YES;
_shouldSearchInBackground = NO;
_shouldSortResults = YES;
_shouldSearchInBackground = NO;
_resultsArray = [NSMutableArray array];

_tokenField = [[TITokenField alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, 42)];
Expand Down Expand Up @@ -484,7 +484,7 @@ - (void)setup {
[self.layer setShadowRadius:12];

[self setPromptText:@"To:"];
[self setText:kTextEmpty];
[self setText:kTextEmpty];

_internalDelegate = [[TITokenFieldInternalDelegate alloc] init];
[_internalDelegate setTokenField:self];
Expand All @@ -494,6 +494,7 @@ - (void)setup {
_editable = YES;
_removesTokensOnEndEditing = YES;
_tokenizingCharacters = [NSCharacterSet characterSetWithCharactersInString:@","];
_tokenLimit = -1;
}

#pragma mark Property Overrides
Expand Down Expand Up @@ -633,6 +634,19 @@ - (TIToken *)addTokenWithTitle:(NSString *)title representedObject:(id)object {
return nil;
}

- (void)addTokensWithTitleList:(NSString *)titleList {
if ([titleList length] > 0) {
self.text = titleList;
[self tokenizeText];
}
}

- (void)addTokensWithTitleArray:(NSArray *)titleArray {
for (NSString *title in titleArray) {
[self addTokenWithTitle:title];
}
}

- (void)addToken:(TIToken *)token {

BOOL shouldAdd = YES;
Expand Down Expand Up @@ -986,6 +1000,11 @@ - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRang
if ([_delegate respondsToSelector:@selector(textField:shouldChangeCharactersInRange:replacementString:)]){
return [_delegate textField:textField shouldChangeCharactersInRange:range replacementString:string];
}

if (_tokenField.tokenLimit!=-1 &&
[_tokenField.tokens count] >= _tokenField.tokenLimit) {
return NO;
}

return YES;
}
Expand Down

0 comments on commit 76ef9d4

Please sign in to comment.