@@ -29,6 +29,8 @@ @interface SLKTextInputbar ()
29
29
@property (nonatomic , strong ) NSLayoutConstraint *bottomMarginWC;
30
30
@property (nonatomic , strong ) NSLayoutConstraint *rightButtonWC;
31
31
@property (nonatomic , strong ) NSLayoutConstraint *rightMarginWC;
32
+ @property (nonatomic , strong ) NSLayoutConstraint *rightButtonTopMarginC;
33
+ @property (nonatomic , strong ) NSLayoutConstraint *rightButtonBottomMarginC;
32
34
@property (nonatomic , strong ) NSLayoutConstraint *editorContentViewHC;
33
35
@property (nonatomic , strong ) NSArray *charCountLabelVCs;
34
36
@@ -92,6 +94,7 @@ - (void)slk_commonInit
92
94
[[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (slk_didChangeTextViewContentSize: ) name: SLKTextViewContentSizeDidChangeNotification object: nil ];
93
95
94
96
[self .leftButton.imageView addObserver: self forKeyPath: NSStringFromSelector (@selector (image )) options: NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context: NULL ];
97
+ [self .rightButton.titleLabel addObserver: self forKeyPath: NSStringFromSelector (@selector (font )) options: NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context: NULL ];
95
98
}
96
99
97
100
@@ -580,11 +583,8 @@ - (void)slk_didChangeTextViewContentSize:(NSNotification *)notification
580
583
581
584
- (void )slk_setupViewConstraints
582
585
{
583
- UIImage *leftButtonImg = [self .leftButton imageForState: UIControlStateNormal];
584
-
585
586
[self .rightButton sizeToFit ];
586
587
587
- CGFloat leftVerMargin = (self.intrinsicContentSize .height - leftButtonImg.size .height ) / 2.0 ;
588
588
CGFloat rightVerMargin = (self.intrinsicContentSize .height - CGRectGetHeight (self.rightButton .frame )) / 2.0 ;
589
589
590
590
NSDictionary *views = @{@" textView" : self.textView ,
@@ -598,7 +598,6 @@ - (void)slk_setupViewConstraints
598
598
@" bottom" : @(self.contentInset .bottom ),
599
599
@" left" : @(self.contentInset .left ),
600
600
@" right" : @(self.contentInset .right ),
601
- @" leftVerMargin" : @(leftVerMargin),
602
601
@" rightVerMargin" : @(rightVerMargin),
603
602
@" minTextViewHeight" : @(self.textView .intrinsicContentSize .height ),
604
603
};
@@ -621,6 +620,9 @@ - (void)slk_setupViewConstraints
621
620
622
621
self.rightButtonWC = [self slk_constraintForAttribute: NSLayoutAttributeWidth firstItem: self .rightButton secondItem: nil ];
623
622
self.rightMarginWC = [self slk_constraintsForAttribute: NSLayoutAttributeTrailing][0 ];
623
+
624
+ self.rightButtonTopMarginC = [self slk_constraintForAttribute: NSLayoutAttributeTop firstItem: self .rightButton secondItem: self ];
625
+ self.rightButtonBottomMarginC = [self slk_constraintForAttribute: NSLayoutAttributeBottom firstItem: self secondItem: self .rightButton];
624
626
}
625
627
626
628
- (void )slk_updateConstraintConstants
@@ -652,6 +654,13 @@ - (void)slk_updateConstraintConstants
652
654
653
655
self.rightButtonWC .constant = [self slk_appropriateRightButtonWidth ];
654
656
self.rightMarginWC .constant = [self slk_appropriateRightButtonMargin ];
657
+
658
+ [self .rightButton sizeToFit ];
659
+
660
+ CGFloat rightVerMargin = (self.intrinsicContentSize .height - CGRectGetHeight (self.rightButton .frame )) / 2.0 ;
661
+
662
+ self.rightButtonTopMarginC .constant = rightVerMargin;
663
+ self.rightButtonBottomMarginC .constant = rightVerMargin;
655
664
}
656
665
}
657
666
@@ -669,6 +678,9 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
669
678
670
679
[self slk_updateConstraintConstants ];
671
680
}
681
+ else if ([object isEqual: self .rightButton.titleLabel] && [keyPath isEqualToString: NSStringFromSelector (@selector (font ))]) {
682
+ [self slk_updateConstraintConstants ];
683
+ }
672
684
else {
673
685
[super observeValueForKeyPath: keyPath ofObject: object change: change context: context];
674
686
}
@@ -683,6 +695,7 @@ - (void)dealloc
683
695
[[NSNotificationCenter defaultCenter ] removeObserver: self name: SLKTextViewContentSizeDidChangeNotification object: nil ];
684
696
685
697
[_leftButton.imageView removeObserver: self forKeyPath: NSStringFromSelector (@selector (image ))];
698
+ [_rightButton.titleLabel removeObserver: self forKeyPath: NSStringFromSelector (@selector (font ))];
686
699
687
700
_leftButton = nil ;
688
701
_rightButton = nil ;
@@ -701,6 +714,8 @@ - (void)dealloc
701
714
_bottomMarginWC = nil ;
702
715
_rightButtonWC = nil ;
703
716
_rightMarginWC = nil ;
717
+ _rightButtonTopMarginC = nil ;
718
+ _rightButtonBottomMarginC = nil ;
704
719
_editorContentViewHC = nil ;
705
720
}
706
721
0 commit comments