From 2532fd0c61307ae86d27acc55b4e9960e68f039e Mon Sep 17 00:00:00 2001 From: Martin Kortkamp Date: Wed, 3 Jan 2018 14:21:39 +0100 Subject: [PATCH] leftbutton: fixed text-only button not displayed When using only a label for the left button it previously wasn't displayed at all. This was due to constraints recalculation was only done when the image is changed but not when the label is changed. Now label is monitored for changes too and constraints are coreetly updated therefore displaying text-only buttons corretly. --- Source/SLKTextInputbar.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/SLKTextInputbar.m b/Source/SLKTextInputbar.m index ca970691..bd331b77 100644 --- a/Source/SLKTextInputbar.m +++ b/Source/SLKTextInputbar.m @@ -105,6 +105,8 @@ - (void)slk_commonInit [self slk_registerTo:self.layer forSelector:@selector(position)]; [self slk_registerTo:self.leftButton.imageView forSelector:@selector(image)]; + [self slk_registerTo:self.leftButton.titleLabel forSelector:@selector(font)]; + [self slk_registerTo:self.leftButton.titleLabel forSelector:@selector(text)]; [self slk_registerTo:self.rightButton.titleLabel forSelector:@selector(font)]; } @@ -706,7 +708,7 @@ - (void)slk_updateConstraintConstants else { self.editorContentViewHC.constant = zero; - CGSize leftButtonSize = [self.leftButton imageForState:self.leftButton.state].size; + CGSize leftButtonSize = [self.leftButton intrinsicContentSize]; if (leftButtonSize.width > 0) { self.leftButtonHC.constant = roundf(leftButtonSize.height); @@ -762,6 +764,11 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N [self slk_updateConstraintConstants]; } } + else if ([object isEqual:self.leftButton.titleLabel] && + ([keyPath isEqualToString:NSStringFromSelector(@selector(font))] + || [keyPath isEqualToString:NSStringFromSelector(@selector(text))])) { + [self slk_updateConstraintConstants]; + } else if ([object isEqual:self.rightButton.titleLabel] && [keyPath isEqualToString:NSStringFromSelector(@selector(font))]) { [self slk_updateConstraintConstants];