iOS 自定義包含PlaceHolder的TextView

因?yàn)槊看问褂肨extView的時(shí)候幾乎都需要PlaceHolder,而系統(tǒng)TextView中并不像TextField一樣有PlaceHolder功能,這用起來(lái)就很尷尬了,而且系統(tǒng)TextView和TextField輸入時(shí),內(nèi)容會(huì)不停跳動(dòng),所以我就干脆封裝一個(gè)好用的TextView,至少我覺得是挺好用的。

內(nèi)容很簡(jiǎn)單只是簡(jiǎn)單地封裝了一下,不過(guò)平時(shí)使用也夠了

這個(gè)textView和比系統(tǒng)的增加了以下一些字段,算了懶得粘貼了

給個(gè)地址自己看下吧 ?這里是地址


這是用法

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

_textView.textFont = [UIFont systemFontOfSize:15];

_textView.placeholderStr = @"請(qǐng)輸入備注,最多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];

這就可以了,如果需要對(duì)輸入動(dòng)作監(jiān)聽,這個(gè)方法要這么寫

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

[_textView textViewDidChange:textView];

~~~~~~~~~~~~這里是你要寫的內(nèi)容~~~~~~~~~~~~~

}

因?yàn)槲野驯O(jiān)聽內(nèi)容改變的方法寫到了類中來(lái)控制PlaceHolder的顯示。就這

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容