UITextView

基本属性

  1. text: 文本.
  2. font: 字体.
  3. textColor: 文本颜色.
  4. textAlignment: 文本内容对齐方式.
  5. selectedRange: 所选择文字在整个字符串的位置.
  6. editable: 是否允许编辑.
  7. selectable: 是否可以选中.
  8. dataDetectorTypes: 判断数据类型,UIWebView、UITextView都有dataDetectorTypes属性,设置了该属性,系统可以自动检测电话、链接、地址、日历、邮箱。并且可以点击,当点击的时候可以在API中自定义事件.
  9. allowsEditingTextAttributes: 是否允许编辑Attributes的文本.
  10. attributedText: 富文本文字.
  11. typingAttributes: 重新设置改变文字的属性字典.
NSMutableDictionary * attributesDic = [textView.typingAttributes mutableCopy];
[attributesDic setObject:[UIColor redColor] forKey:NSForegroundColorAttributeName];
// automatically resets when the selection changes
// 重新设置 接下来改变的文字 的属性字典
textView.typingAttributes = attributesDic;
一般在一些代理函数中使用,比如当编辑状态的变化
  1. inputView和inputAccessoryView: 链接
  2. textContainer: 文本区域.(富文本内容.)
  3. textContainerInset: 文本区域和与边界的距离.(富文本内容.)
  4. layoutManager和textStorage: 富文本内容.
  5. linkTextAttributes: 链接文本的样式设置.
  6. 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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值