UITextView 添加placeholder 工作记录1
2017-02-14 本文已影响14人
杨柳小易
因为最近项目中有需求,需要给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定制不同样式的占位符就方便了很多。