博客
关于我
iOS UITextView控件
阅读量:603 次
发布时间:2019-03-11

本文共 2182 字,大约阅读时间需要 7 分钟。

UITextView控件可以输入多行文字并且可以滚动显示浏览全文。

1. 基本属性

属性 说明
text 设置文本
textColor 设置文本的颜色
font 设置文本的字体
textAlignment 设置文本的对齐方式
editable 设置是否可以编辑,默认是YES
selectable 是否可以选中
selectedRange 所选择文字在整个字符串的位置
attributedText 设置富文本
typingAttributes 设置文字的属性字典
allowsEditingTextAttributes 设置是否允许编辑Attributes的文本
inputView 显示键盘的View,重写这个方法则不再弹出键盘,而是我们自定义的view
inputAccessoryView 该view会在键盘上面显示
clearsOnInsertion 获得焦点后选中现有文本,输入内容时清除当前选中文本
dataDetectorTypes 超链接,需要将可编辑状态设置为NO
keyboardType 设置键盘类型,类同于
returnKeyType 设置键盘上返回键的类型,类同于
keyboardAppearance 设置键盘的视觉样式,类同于

UIDataDetectorTypes属性

属性 说明
UIDataDetectorTypePhoneNumber 检测格式化为电话号码的字符串。
UIDataDetectorTypeLink 检测格式为URL的字符串。
UIDataDetectorTypeAddress 检测格式为地址的字符串。
UIDataDetectorTypeCalendarEvent 检测格式化为日历事件的字符串。
UIDataDetectorTypeShipmentTrackingNumber 检测格式化为包裹递送公司的跟踪号码的字符串。
UIDataDetectorTypeFlightNumber 检测格式化为航空公司航班号的字符串。
UIDataDetectorTypeLookupSuggestion 检测格式化为用户可能要查找的信息的字符串。
UIDataDetectorTypeNone 不支持超链接
UIDataDetectorTypeAll 接收所有类型的字符串

2. 方法

方法名 说明
- (void)scrollRangeToVisible:(NSRange)range 滚动到指定 range

3. UITextViewDelegate代理设置

UITextViewDelegate的方法

// 将要开始编辑- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;// 将要结束编辑- (BOOL)textViewShouldEndEditing:(UITextView *)textView;// 已经开始编辑- (void)textViewDidBeginEditing:(UITextView *)textView;// 已经结束编辑- (void)textViewDidEndEditing:(UITextView *)textView;// 文本将要改变- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;// 文本发生改变- (void)textViewDidChange:(UITextView *)textView;// 焦点发生改变- (void)textViewDidChangeSelection:(UITextView *)textView;// 是否允许对文本中的URL进行操作- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction NS_AVAILABLE_IOS(10_0);// 是否允许对文本中的富文本进行操作- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction NS_AVAILABLE_IOS(10_0);

4. UITextView相关通知

通知名 说明
UITextViewTextDidBeginEditingNotification 开始编辑
UITextViewTextDidChangeNotification 文本发生变化
UITextViewTextDidEndEditingNotification 编辑结束的通知

源码下载:

相关文章

转载地址:http://njpvz.baihongyu.com/

你可能感兴趣的文章
mysql中kill掉所有锁表的进程
查看>>
mysql中like % %模糊查询
查看>>
MySql中mvcc学习记录
查看>>
mysql中null和空字符串的区别与问题!
查看>>