diff --git a/VENTokenField/VENTokenField.h b/VENTokenField/VENTokenField.h index 73ea5dd..be5800c 100644 --- a/VENTokenField/VENTokenField.h +++ b/VENTokenField/VENTokenField.h @@ -37,6 +37,7 @@ - (NSUInteger)numberOfTokensInTokenField:(VENTokenField *)tokenField; - (NSString *)tokenFieldCollapsedText:(VENTokenField *)tokenField; - (UIColor *)tokenField:(VENTokenField *)tokenField colorSchemeForTokenAtIndex:(NSUInteger)index; +- (Class)subclassForTokensInTokenField:(VENTokenField *)tokenField; @end diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 63c63a6..d0a4c10 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -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; @@ -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