From 6b1e78970d85ba39bb987503292c11eb0eb9f6f7 Mon Sep 17 00:00:00 2001 From: Dasmer Singh Date: Mon, 21 Dec 2015 14:48:43 -0500 Subject: [PATCH 1/2] Create delegate method for changes in tokenFieldHeight --- VENTokenField/VENTokenField.h | 1 + VENTokenField/VENTokenField.m | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/VENTokenField/VENTokenField.h b/VENTokenField/VENTokenField.h index cb1e87e..973bcbd 100644 --- a/VENTokenField/VENTokenField.h +++ b/VENTokenField/VENTokenField.h @@ -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 diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index cc41048..f8e8214 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -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 From a6c26aac8cf504ba56610558a370f5fa44eaa998 Mon Sep 17 00:00:00 2001 From: Dasmer Singh Date: Tue, 22 Dec 2015 12:51:28 -0500 Subject: [PATCH 2/2] Ensure backwards compatibility --- VENTokenField/VENTokenField.m | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index f8e8214..afcc026 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -390,9 +390,11 @@ - (void)adjustHeightForCurrentY:(CGFloat)currentY height = self.originalHeight; } } - if (oldHeight != height - && [self.delegate respondsToSelector:@selector(tokenField:didChangeContentHeight:)]) { - [self.delegate tokenField:self didChangeContentHeight:height]; + if (oldHeight != height) { + [self setHeight:height]; + if ([self.delegate respondsToSelector:@selector(tokenField:didChangeContentHeight:)]) { + [self.delegate tokenField:self didChangeContentHeight:height]; + } } }