Skip to content

Commit b566481

Browse files
louosoGraham Chance
authored andcommitted
exposing the floating label text
allowing the label to differ from the placeholder if needed
1 parent f2b1df7 commit b566481

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

MaterialTextField/MFTextField.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,9 @@ IB_DESIGNABLE
9898
*/
9999
@property (nonatomic) IBInspectable CGSize errorPadding;
100100

101+
/**
102+
* The text that is displayed above the text field when there is input.
103+
*/
104+
@property (nonatomic) NSString *floatingLabelText;
105+
101106
@end

MaterialTextField/MFTextField.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ - (void)setAttributedText:(NSAttributedString *)attributedText
206206
[self updateDefaultPlaceholderFont];
207207
}
208208

209+
- (void)setFloatingLabelText:(NSString *)floatingLabelText
210+
{
211+
_floatingLabelText = floatingLabelText;
212+
[self updatePlaceholderText];
213+
}
214+
209215
- (void)setPlaceholder:(NSString *)placeholder
210216
{
211217
[super setPlaceholder:placeholder];
@@ -492,7 +498,8 @@ - (void)hidePlaceholderLabelAnimated:(BOOL)animated
492498

493499
- (void)updatePlaceholderText
494500
{
495-
self.placeholderLabel.text = self.placeholder ?: self.placeholderAttributedString.string;
501+
NSString * actualPlaceholder = self.placeholder ?: self.placeholderAttributedString.string;
502+
self.placeholderLabel.text = self.floatingLabelText ?: actualPlaceholder;
496503
[self.placeholderLabel sizeToFit];
497504
[self invalidateIntrinsicContentSize];
498505
}

0 commit comments

Comments
 (0)