因為最近項目中有需求,需要給UITextView 中添加 placeholder
之前版本的使用方式直接是在xib中給UITextView 中添加UILabel,或者 UIImageView
恰好項目中有使用IQTextView,改造了一下IQTextView 適應了現在的需求。
@interface IQTextView : UITextView
/**
Set textView's placeholder text. Default is nil.*/
@property(nonatomic,copy) NSString *placeholder;
@property(nonatomic,copy) NSAttributedString *attrbutePlaceholder;
@end
反思,這種第三方庫如果使用pod引入,直接改動源碼的形式是不行的。應該使用runtime或者自己實現一個全局的UITextView的placeholder分類。attrbutePlaceholder定制不同樣式的占位符就方便了很多。