Skip to content

Commit b339604

Browse files
authored
Merge pull request #1 from hoangtaiki/develop
Implement function to setHidden for left button at TextInputBar
2 parents 3c99367 + 191337d commit b339604

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

Source/SLKTextInputbar.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ NS_ASSUME_NONNULL_BEGIN
4848
/** The right action button action. */
4949
@property (nonatomic, strong) UIButton *rightButton;
5050

51+
/** YES if the right button should be hidden animatedly in case the text view has no text in it. Default is YES. */
52+
@property (nonatomic, readwrite) BOOL leftButtonIsHidden;
53+
5154
/** YES if the right button should be hidden animatedly in case the text view has no text in it. Default is YES. */
5255
@property (nonatomic, readwrite) BOOL autoHideRightButton;
5356

@@ -119,6 +122,11 @@ NS_ASSUME_NONNULL_BEGIN
119122
*/
120123
- (void)endTextEdition;
121124

125+
/**
126+
Set hidden state for left button.
127+
*/
128+
- (void)setLeftButtonHidden:(BOOL)isHidden;
129+
122130

123131
#pragma mark - Text Counting
124132
///------------------------------------------------

Source/SLKTextInputbar.m

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ - (void)slk_commonInit
8181
self.charCountLabelWarningColor = [UIColor redColor];
8282

8383
self.autoHideRightButton = YES;
84+
self.leftButtonIsHidden = YES;
8485
self.editorContentViewHeight = 38.0;
8586
self.contentInset = UIEdgeInsetsMake(5.0, 8.0, 5.0, 8.0);
8687

@@ -517,6 +518,13 @@ - (void)setCounterPosition:(SLKCounterPosition)counterPosition
517518
[self addConstraints:self.charCountLabelVCs];
518519
}
519520

521+
- (void)setLeftButtonHidden:(BOOL)isHidden
522+
{
523+
self.leftButtonIsHidden = isHidden;
524+
CGFloat leftButtonWidth = isHidden ? 0 : [self.rightButton intrinsicContentSize].width;
525+
self.leftButton.hidden = isHidden;
526+
self.leftButtonWC.constant = leftButtonWidth;
527+
}
520528

521529
#pragma mark - Text Editing
522530

@@ -713,8 +721,13 @@ - (void)slk_updateConstraintConstants
713721
self.leftButtonBottomMarginC.constant = roundf((self.intrinsicContentSize.height - leftButtonSize.height) / 2.0) + self.slk_contentViewHeight / 2.0;
714722
}
715723

716-
self.leftButtonWC.constant = roundf(leftButtonSize.width);
717-
self.leftMarginWC.constant = (leftButtonSize.width > 0) ? self.contentInset.left : zero;
724+
if (self.leftButtonIsHidden) {
725+
self.leftButtonWC.constant = 0;
726+
self.leftMarginWC.constant = zero;
727+
} else {
728+
self.leftButtonWC.constant = roundf(leftButtonSize.width);
729+
self.leftMarginWC.constant = (leftButtonSize.width > 0) ? self.contentInset.left : zero;
730+
}
718731

719732
self.rightButtonWC.constant = [self slk_appropriateRightButtonWidth];
720733
self.rightMarginWC.constant = [self slk_appropriateRightButtonMargin];

0 commit comments

Comments
 (0)