Skip to content

Commit

Permalink
Merge pull request #85 from venmo/daz/changeHeight
Browse files Browse the repository at this point in the history
Create delegate method for changes in tokenFieldHeight
  • Loading branch information
dasmer committed Jan 6, 2016
2 parents 7ca4e1f + a6c26aa commit 3f55203
Show file tree
Hide file tree
Showing 2 changed files with 13 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
16 changes: 12 additions & 4 deletions VENTokenField/VENTokenField.m
Original file line number Diff line number Diff line change
Expand Up @@ -375,17 +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 setHeight:height];
if ([self.delegate respondsToSelector:@selector(tokenField:didChangeContentHeight:)]) {
[self.delegate tokenField:self didChangeContentHeight:height];
}
}
}
Expand Down

0 comments on commit 3f55203

Please sign in to comment.