diff --git a/MaterialTextField/MFTextField.h b/MaterialTextField/MFTextField.h old mode 100644 new mode 100755 index 210e2bd..856c748 --- a/MaterialTextField/MFTextField.h +++ b/MaterialTextField/MFTextField.h @@ -28,6 +28,12 @@ IB_DESIGNABLE */ @property (nonatomic) IBInspectable BOOL placeholderAnimatesOnFocus; + +/** + * Default is NO. If YES, the placeholder label will be always visible + */ +@property (nonatomic) IBInspectable BOOL alwaysShowPlaceholderOnTop; + /** * The color of the text field's default placeholder (displayed when text field is empty). */ diff --git a/MaterialTextField/MFTextField.m b/MaterialTextField/MFTextField.m old mode 100644 new mode 100755 index a45b10d..cfb680b --- a/MaterialTextField/MFTextField.m +++ b/MaterialTextField/MFTextField.m @@ -76,6 +76,7 @@ - (void)setDefaults self.textPadding = CGSizeMake(0.0f, 8.0f); self.errorPadding = CGSizeMake(0.0f, 4.0f); + self.alwaysShowPlaceholderOnTop = NO; self.animatesPlaceholder = YES; self.placeholderColor = [UIColor mf_darkGrayColor]; self.placeholderFont = self.defaultPlaceholderFont; @@ -243,6 +244,15 @@ - (void)setAnimatesPlaceholder:(BOOL)animatesPlaceholder } } +- (void)setAlwaysShowPlaceholderOnTop:(BOOL)alwaysShowPlaceholderOnTop +{ + _alwaysShowPlaceholderOnTop = alwaysShowPlaceholderOnTop; + if (alwaysShowPlaceholderOnTop) + { + self.placeholderLabel.alpha = 1; + } +} + - (void)setDefaultPlaceholderColor:(UIColor *)defaultPlaceholderColor { _defaultPlaceholderColor = defaultPlaceholderColor ?: [UIColor mf_defaultPlaceholderGray]; @@ -299,7 +309,7 @@ - (BOOL)shouldShowPlaceholder { BOOL isEmpty = self.text.length == 0; - return !isEmpty || (self.placeholderAnimatesOnFocus && self.isFirstResponder); + return !isEmpty || self.alwaysShowPlaceholderOnTop || (self.placeholderAnimatesOnFocus && self.isFirstResponder); } - (BOOL)hasError