为UITextView增加占位文字的封装

2016-11-24  本文已影响0人  怪兽密保
1.新建继承UITextView的类

定义可以对外访问用于修改的属性
<pre>
/** 占位文字 */
@property (nonatomic, copy) NSString *placeholder;
/** 占位文字的颜色 */
@property (nonatomic, strong) UIColor *placeholderColor;
</pre>

在.m文件定义一个label

<pre>
/** 占位文字label */
@property (nonatomic, weak) UILabel *placeholderLabel;
</pre>

懒加载把label添加到textView中

<pre>

初始化一些设置

<pre>

</pre>

移除通知

<pre>

更新占位文字的尺寸

<pre>

重写相关的setting方法

<pre>

封装的类的下载地址https://git.oschina.net/qjz.com/TextView_placeholderLabel/tree/master

上一篇 下一篇

猜你喜欢

热点阅读