iOS 自定义包含PlaceHolder的TextView

因为每次使用TextView的时候几乎都需要PlaceHolder,而系统TextView中并不像TextField一样有PlaceHolder功能,这用起来就很尴尬了,而且系统TextView和TextField输入时,内容会不停跳动,所以我就干脆封装一个好用的TextView,至少我觉得是挺好用的。

内容很简单只是简单地封装了一下,不过平时使用也够了

这个textView和比系统的增加了以下一些字段,算了懒得粘贴了

给个地址自己看下吧  这里是地址


这是用法

_textView = [[BGTextView alloc] initWithFrame:CGRectMake(15, button.allHeight + 10, _centerView.sizeWidth - 30, 0)];

_textView.textFont = [UIFont systemFontOfSize:15];

_textView.placeholderStr = @"请输入备注,最多50字哦!";

_textView.placeholderColor = kColorFrom0x(0xbebebe);

_textView.textViewTextColor = [UIColor blackColor];

_textView.backgroundColor = kColorFrom0x(0xf4f4f4);

_textView.tintColor = [UIColor blackColor];

_textView.keyboardType = UIKeyboardTypeNumberPad;

[_textView updateInfo];

_textView.delegate = self;(UITextViewDelegate)

[self.view addSubview:_textView];

这就可以了,如果需要对输入动作监听,这个方法要这么写

- (void)textViewDidChange:(UITextView *)textView{

[_textView textViewDidChange:textView];

~~~~~~~~~~~~这里是你要写的内容~~~~~~~~~~~~~

}

因为我把监听内容改变的方法写到了类中来控制PlaceHolder的显示。就这

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容