Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a VENTokenFieldDataSource method to provide a VENToken subclass #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions VENTokenField/VENTokenField.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- (NSUInteger)numberOfTokensInTokenField:(VENTokenField *)tokenField;
- (NSString *)tokenFieldCollapsedText:(VENTokenField *)tokenField;
- (UIColor *)tokenField:(VENTokenField *)tokenField colorSchemeForTokenAtIndex:(NSUInteger)index;
- (Class)subclassForTokensInTokenField:(VENTokenField *)tokenField;
@end


Expand Down
16 changes: 15 additions & 1 deletion VENTokenField/VENTokenField.m
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ - (void)layoutTokensWithCurrentX:(CGFloat *)currentX currentY:(CGFloat *)current
{
for (NSUInteger i = 0; i < [self numberOfTokens]; i++) {
NSString *title = [self titleForTokenAtIndex:i];
VENToken *token = [[VENToken alloc] init];
VENToken *token = [[[self subclassForTokens] alloc] init];

__weak VENToken *weakToken = token;
__weak VENTokenField *weakSelf = self;
Expand Down Expand Up @@ -527,6 +527,20 @@ - (NSString *)collapsedText
return @"";
}

- (Class)subclassForTokens
{
Class defaultClass = [VENToken class];

if ([self.dataSource respondsToSelector:@selector(subclassForTokensInTokenField:)]) {
Class providedSubclass = [self.dataSource subclassForTokensInTokenField:self];
if ([providedSubclass isSubclassOfClass:defaultClass]) {
return providedSubclass;
}
}

return defaultClass;
}


#pragma mark - UITextFieldDelegate

Expand Down