1.#pragma mark Lazy ------------ 懶加載創建UITextview
- (UITextview *)viewText {
if (!_viewText) {
_viewText =[[UITextview alloc]init];
_viewText.text = @"textView";
_viewText.font = kSystemFont(15);
_viewText.textColor = COLOR_WHITE;
[_viewText setShowsVerticalScrollIndicator:NO];
[_viewText setShowsHorizontalScrollIndicator:NO];
_viewText.delegate = self;
_viewText.backgroundColor = COLOR_SYSTEM_VIEW_BACKGROUND;
}
return _viewText;
}
2. #pragma mark initTextView ------------ add to self.view and regist NSNotificationCenter
- (void)initTextView {
[self.view addSubview:self.viewText];
[self.viewText mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_bottom);
make.bottom.equalTo(self.view.mas_top);
make.width.equalTo(self.view);
}];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textViewEditeAction:)name:UITextViewTextDidChangeNotification object:nil];
3. #pragma mark Action ------------ textViewEditeAction 監聽文本被修改
- (void)textViewEditeAction:(UITextView *)sender {
NSLog(@"sender %@ ",self.viewText.selectedRange.location);
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
iOS Object-C UITextview 監聽文本改動
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
推薦閱讀更多精彩內容
- iOS_autoLayout_Masonry 概述 Masonry是一個輕量級的布局框架與更好的包裝AutoLay...