diff --git a/IQKeyboardManager/IQTextView/IQTextView.h b/IQKeyboardManager/IQTextView/IQTextView.h index 8ff18593..99a9bfa1 100644 --- a/IQKeyboardManager/IQTextView/IQTextView.h +++ b/IQKeyboardManager/IQTextView/IQTextView.h @@ -35,6 +35,11 @@ */ @property(nullable, nonatomic,copy) IBInspectable NSString *placeholder; +/** + Set textView's placeholder attributed text. Default is nil. + */ +@property(nullable, nonatomic,copy) IBInspectable NSAttributedString *attributedPlaceholder; + /** To set textView's placeholder text color. Default is nil. */ diff --git a/IQKeyboardManager/IQTextView/IQTextView.m b/IQKeyboardManager/IQTextView/IQTextView.m index f451552d..c4638a80 100644 --- a/IQKeyboardManager/IQTextView/IQTextView.m +++ b/IQKeyboardManager/IQTextView/IQTextView.m @@ -68,7 +68,7 @@ -(void)awakeFromNib -(void)refreshPlaceholder { - if([[self text] length]) + if([[self text] length] || [[self attributedText] length]) { [_placeholderLabel setAlpha:0]; } @@ -87,6 +87,12 @@ - (void)setText:(NSString *)text [self refreshPlaceholder]; } +-(void)setAttributedText:(NSAttributedString *)attributedText +{ + [super setAttributedText:attributedText]; + [self refreshPlaceholder]; +} + -(void)setFont:(UIFont *)font { [super setFont:font]; @@ -119,6 +125,14 @@ -(void)setPlaceholder:(NSString *)placeholder [self refreshPlaceholder]; } +-(void)setAttributedPlaceholder:(NSAttributedString *)attributedPlaceholder +{ + _attributedPlaceholder = attributedPlaceholder; + + self.placeholderLabel.attributedText = attributedPlaceholder; + [self refreshPlaceholder]; +} + -(void)setPlaceholderTextColor:(UIColor*)placeholderTextColor { _placeholderTextColor = placeholderTextColor; diff --git a/IQKeyboardManagerSwift/IQTextView/IQTextView.swift b/IQKeyboardManagerSwift/IQTextView/IQTextView.swift index 47ac9476..3f7ec316 100644 --- a/IQKeyboardManagerSwift/IQTextView/IQTextView.swift +++ b/IQKeyboardManagerSwift/IQTextView/IQTextView.swift @@ -141,7 +141,7 @@ open class IQTextView : UITextView { @objc internal func refreshPlaceholder() { - if !text.isEmpty { + if !text.isEmpty || !attributedText.string.isEmpty { placeholderLabel.alpha = 0 } else { placeholderLabel.alpha = 1 @@ -151,9 +151,14 @@ open class IQTextView : UITextView { @objc override open var text: String! { didSet { - refreshPlaceholder() - + } + } + + open override var attributedText: NSAttributedString! { + + didSet { + refreshPlaceholder() } }