UITextView头文件学习

来源:互联网 发布:js滑动幻灯片轮播代码 编辑:程序博客网 时间:2024/06/06 01:08

UITextViewDelegate中可选择实现的方法:


//将要开始编辑时

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;


//将要结束编辑时

- (BOOL)textViewShouldEndEditing:(UITextView *)textView;


//开始编辑

- (void)textViewDidBeginEditing:(UITextView *)textView;


//结束编辑

- (void)textViewDidEndEditing:(UITextView *)textView;


//某个范围的文本将要改变时(可以用来控制文本字数,通过range判断,可以禁止输入某个字符,通过text判断

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;


//文本改变时(例如textview高度适应文本内容高度)

- (void)textViewDidChange:(UITextView *)textView;


//焦点发生改变时

- (void)textViewDidChangeSelection:(UITextView *)textView;


关于UITextView退出键盘的几种方式可参考:http://blog.sina.com.cn/s/blog_9693f61a0101aode.html


常用的属性:

@property(nullable,nonatomic,weak)id<UITextViewDelegate> delegate; 在viewcontroller中实现协议和方法,设置textview的代理为该viewcontroller


@property(null_resettable,nonatomic,copy)NSString *text;  文本内容

@property(nullable,nonatomic,strong)UIFont *font;         文本的字体

@property(nullable,nonatomic,strong)UIColor *textColor;   文本颜色

@property(nonatomic)NSTextAlignment textAlignment;        文本排列方式,默认是居左

@property(nonatomic)NSRange selectedRange;                文本中被选择的区域


@property(nonatomic,getter=isEditable)BOOL editable __TVOS_PROHIBITED;           是否可编辑

@property(nonatomic,getter=isSelectable)BOOL selectableNS_AVAILABLE_IOS(7_0);   是否可选中

@property(nonatomic)UIDataDetectorTypes dataDetectorTypesNS_AVAILABLE_IOS(3_0)__TVOS_PROHIBITED; 数据类型检测

(超链接、电话号码、邮件地址等)


@property(nonatomic)BOOL allowsEditingTextAttributesNS_AVAILABLE_IOS(6_0);     是否允许更改字符属性字典

@property(null_resettable,copy)NSAttributedString *attributedTextNS_AVAILABLE_IOS(6_0); 通过AttributedString创建和获取文字

@property(nonatomic)BOOL clearsOnInsertion NS_AVAILABLE_IOS(6_0);           是否允许再次编辑时在内容中间插入内容


- (void)scrollRangeToVisible:(NSRange)range; 滚动textview到某一位置


关于 inputView 和 inputAccessoryView:

inputAccessoryView是显示在键盘上方的自定义view,会随键盘一起弹出,自定义一个view(例如UIToolbar),赋值给inputAccessoryView就行了。

inputView 即是弹出键盘的view,如果重写该inputView,自定义的view会取代键盘弹出(例如日期选择器),设置了inputView只有当textview变为第一响应者的时候弹出


http://www.360doc.com/content/15/0202/17/20917840_445752308.shtml(可能遇到的问题)


0 0