基本属性
- text: 文本.
- font: 字体.
- textColor: 文本颜色.
- textAlignment: 文本内容对齐方式.
- selectedRange: 所选择文字在整个字符串的位置.
- editable: 是否允许编辑.
- selectable: 是否可以选中.
- dataDetectorTypes: 判断数据类型,UIWebView、UITextView都有dataDetectorTypes属性,设置了该属性,系统可以自动检测电话、链接、地址、日历、邮箱。并且可以点击,当点击的时候可以在API中自定义事件.
- allowsEditingTextAttributes: 是否允许编辑Attributes的文本.
- attributedText: 富文本文字.
- typingAttributes: 重新设置改变文字的属性字典.
NSMutableDictionary * attributesDic = [textView.typingAttributes mutableCopy];
[attributesDic setObject:[UIColor redColor] forKey:NSForegroundColorAttributeName];
// automatically resets when the selection changes
// 重新设置 接下来改变的文字 的属性字典
textView.typingAttributes = attributesDic;
一般在一些代理函数中使用,比如当编辑状态的变化
- inputView和inputAccessoryView: 链接
- textContainer: 文本区域.(富文本内容.)
- textContainerInset: 文本区域和与边界的距离.(富文本内容.)
- layoutManager和textStorage: 富文本内容.
- linkTextAttributes: 链接文本的样式设置.
- clearsOnInsertion: 获得焦点后选中现有文本,输入内容时清除当前选中文本.
方法
// 滚动到指定 range
- (void)scrollRangeToVisible:(NSRange)range;
代理方法
// 将要开始编辑
- (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);
通知
// 开始编辑的通知
UITextViewTextDidBeginEditingNotification;
//文本发生变化的通知
UITextViewTextDidChangeNotification;
//编辑结束的通知
UITextViewTextDidEndEditingNotification;