因?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的顯示。就這