Skip to content

Commit

Permalink
Improved #1411
Browse files Browse the repository at this point in the history
  • Loading branch information
hackiftekhar committed Oct 8, 2018
1 parent faced0d commit b36bd79
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
5 changes: 5 additions & 0 deletions IQKeyboardManager/IQTextView/IQTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
16 changes: 15 additions & 1 deletion IQKeyboardManager/IQTextView/IQTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ -(void)awakeFromNib

-(void)refreshPlaceholder
{
if([[self text] length])
if([[self text] length] || [[self attributedText] length])
{
[_placeholderLabel setAlpha:0];
}
Expand All @@ -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];
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions IQKeyboardManagerSwift/IQTextView/IQTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -151,9 +151,14 @@ open class IQTextView : UITextView {
@objc override open var text: String! {

didSet {

refreshPlaceholder()

}
}

open override var attributedText: NSAttributedString! {

didSet {
refreshPlaceholder()
}
}

Expand Down

0 comments on commit b36bd79

Please sign in to comment.