Skip to content

Commit 3eab81a

Browse files
committed
exposing the floating label text
allowing the label to differ from the placeholder if needed
1 parent c621c8a commit 3eab81a

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
@@ -97,4 +97,9 @@ IB_DESIGNABLE
9797
*/
9898
@property (nonatomic) IBInspectable CGFloat errorPadding;
9999

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

MaterialTextField/MFTextField.m

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

198+
- (void)setFloatingLabelText:(NSString *)floatingLabelText
199+
{
200+
_floatingLabelText = floatingLabelText;
201+
[self updatePlaceholderText];
202+
}
203+
198204
- (void)setPlaceholder:(NSString *)placeholder
199205
{
200206
[super setPlaceholder:placeholder];
@@ -478,7 +484,8 @@ - (void)hidePlaceholderLabelAnimated:(BOOL)animated
478484

479485
- (void)updatePlaceholderText
480486
{
481-
self.placeholderLabel.text = self.placeholder ?: self.placeholderAttributedString.string;
487+
NSString * actualPlaceholder = self.placeholder ?: self.placeholderAttributedString.string;
488+
self.placeholderLabel.text = self.floatingLabelText ?: actualPlaceholder;
482489
[self.placeholderLabel sizeToFit];
483490
[self invalidateIntrinsicContentSize];
484491
}

0 commit comments

Comments
 (0)