Skip to content

Commit

Permalink
Create delegate method for changes in tokenFieldHeight
Browse files Browse the repository at this point in the history
  • Loading branch information
Dasmer Singh committed Dec 21, 2015
1 parent 7ca4e1f commit 6b1e789
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions VENTokenField/VENTokenField.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)tokenField:(VENTokenField *)tokenField didDeleteTokenAtIndex:(NSUInteger)index;
- (void)tokenField:(VENTokenField *)tokenField didChangeText:(nullable NSString *)text;
- (void)tokenFieldDidBeginEditing:(VENTokenField *)tokenField;
- (void)tokenField:(VENTokenField *)tokenField didChangeContentHeight:(CGFloat)height;
@end

@protocol VENTokenFieldDataSource <NSObject>
Expand Down
14 changes: 10 additions & 4 deletions VENTokenField/VENTokenField.m
Original file line number Diff line number Diff line change
Expand Up @@ -375,19 +375,25 @@ - (UILabel *)toLabel

- (void)adjustHeightForCurrentY:(CGFloat)currentY
{
CGFloat oldHeight = self.height;
CGFloat height;
if (currentY + [self heightForToken] > CGRectGetHeight(self.frame)) { // needs to grow
if (currentY + [self heightForToken] <= self.maxHeight) {
[self setHeight:currentY + [self heightForToken] + self.verticalInset * 2];
height = currentY + [self heightForToken] + self.verticalInset * 2;
} else {
[self setHeight:self.maxHeight];
height = self.maxHeight;
}
} else { // needs to shrink
if (currentY + [self heightForToken] > self.originalHeight) {
[self setHeight:currentY + [self heightForToken] + self.verticalInset * 2];
height = currentY + [self heightForToken] + self.verticalInset * 2;
} else {
[self setHeight:self.originalHeight];
height = self.originalHeight;
}
}
if (oldHeight != height
&& [self.delegate respondsToSelector:@selector(tokenField:didChangeContentHeight:)]) {
[self.delegate tokenField:self didChangeContentHeight:height];
}
}

- (VENBackspaceTextField *)inputTextField
Expand Down

0 comments on commit 6b1e789

Please sign in to comment.