ios UITextView 详解

OS中UITextView方法解读

常用属性解读:

@property(nonatomic,assignid<UITextViewDelegate> delegate;

设置代理属性

@property(nonatomic,copyNSString *text;

textView上的文本

@property(nonatomic,retainUIFont *font;

设置文本字体

@property(nonatomic,retainUIColor *textColor;

设置文本颜色

@property(nonatomicNSTextAlignment textAlignment; 

设置文本对齐模式

@property(nonatomicNSRange selectedRange;

设置选中的文本范围(只有当textView是第一响应时才有效)

@property(nonatomic,getter=isEditable) BOOL editable;

设置是否可以编辑

@property(nonatomic,getter=isSelectable) BOOL selectable;

设置是否可以选中


@property(nonatomicUIDataDetectorTypes dataDetectorTypes;

这个属性可以将本文中的电话,邮件等变为链接,长按会调用响应响应的程序(textView必须为不可编辑状态),属性的枚举如下:

?

1
2
3
4
5
6
7
8
typedef  NS_OPTIONS(NSUInteger, UIDataDetectorTypes) {
     UIDataDetectorTypePhoneNumber   = 1 << 0,           // 电话变为链接
     UIDataDetectorTypeLink          = 1 << 1,           // 网址变为链接   
     UIDataDetectorTypeAddress       = 1 << 2,           // 地址变为链接
     UIDataDetectorTypeCalendarEvent = 1 << 3,           // 日历变为链接
     UIDataDetectorTypeNone          = 0,                // 无连接
     UIDataDetectorTypeAll           = NSUIntegerMax     // 所有类型链接
};

@property(nonatomicBOOL allowsEditingTextAttributes;

设置是否允许编辑属性字符串文本

@property(nonatomic,copyNSAttributedString *attributedText;

设置属性字符串文本

@property(nonatomic,copyNSDictionary *typingAttributes;

设置属性字符串文本属性字典


- (void)scrollRangeToVisible:(NSRange)range;

滚动textView使其显示在本一段文本

@property (readwriteretainUIView *inputView;  

设置成为第一响应时弹出的视图,键盘视图

@property (readwriteretainUIView *inputAccessoryView;

设置成为第一响应时弹出的副视图,副键盘视图

@property(nonatomicBOOL clearsOnInsertion;

设置是否显示删除按钮


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;

选中内容改变触发的方法



- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange;

当文本中的URL进行链接时触发的方法

(可以用这shouldInteractWithURL代理方法<返回为NO>和dataDetectorTypes配合使用,实现自定义触发URL的事件)




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值