UITextView 基础篇
2016-03-18 14:34
459 查看
苹果对UITextView的解释:UITextView displays a region that can contain multiple lines of editable text. When a user taps a text view, a keyboard appears; when a user taps Return in the keyboard, the keyboard disappears
and the text view can handle the input in an application-specific way. You can specify attributes, such as font, color, and alignment, that apply to all text in a text view.
大概意思为:UITextView可以编辑多行文本,当UITextView成为第一响应者的时候(进入编辑模式弹出键盘)可以编辑文本。结束编辑的时候可以可以根据自己所设定的特定的文本方式处理响应的文本(包括字体,大小,对其方式,颜色....)
属性:
text:文本
font:字体
textColor:字体颜色
textAlignment:对齐方式 (默认向左对齐)
selectedRange:选择范围(有两个属性location:光标的位置 length:选中的文本的长度)
editable:是否允许编辑(默认是YES允许编辑)
selectable:是否允许选择(默认允许 ios7加入)
dataDetectorTypes:数据检测类型(取值为:UIDataDetectorTypes一共有6种类型:UIDataDetectorTypePhoneNumber:电话文本链接;UIDataDetectorTypeLink:URL链接;UIDataDetectorTypeAddress:地址链接;UIDataDetectorTypeCalendarEvent:日历类型链接;UIDataDetectorTypeNone:没有类型;UIDataDetectorTypeAll:所有类型)只有在不能编辑的情况下这些才能被识别
allowsEditingTextAttributes:允许编辑富文本(默认不允许iOS6加入)
attributedText:富文本
typingAttributes:富文本格式
inputView:输入视图(效果可参考UITextfield)
inputAccessoryView:输入辅助视图 (效果可参考UITextfield)
clearsOnInsertion:是否能修改之前的文本(默认为不能)
textContainer:文本容器(一个矩形区域用于存放已经进行了排版并设置好属性的文字 iOS7加入)
textContainerInset:文本视图的缩进范围(及文本区域的布局iOS7加入)
layoutManager:管理NSTextStorage其中的文字内容的排版布局 (iOS7加入)
textStorage:保存并管理UITextView要展示的文字内容(是NSMutableAttributedString的一个子类iOS7加入)
linkTextAttributes:链接文本的属性(iOS7 加入)
方法:
- (void)scrollRangeToVisible:(NSRange)range;滚动TextView使其显示指定区域的文字
- (instancetype)initWithFrame:(CGRect)frame textContainer:(nullable NSTextContainer *)textContainer ;重新指定文本容器视图的位置内容(iOS7加入)
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder ;反归档
代理:
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView; 是否允许textview进入编辑状态
- (BOOL)textViewShouldEndEditing:(UITextView *)textView; 是否允许textview结束编辑状态
- (void)textViewDidBeginEditing:(UITextView *)textView; textview进入编辑状态后执行的方法(成为第一响应者)
- (void)textViewDidEndEditing:(UITextView *)textView; textview结束编辑状态执行的方法(取消第一响应者)
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text; 是否响应改变当前文本(默认可以该改变,及当前输入的文本有效)
- (void)textViewDidChange:(UITextView *)textView; textview的文本内容发生改变的时候执行的方法
- (void)textViewDidChangeSelection:(UITextView *)textView; 焦点发生改变执行的方法
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange; 是否能够给textview添加超链接及点击超链接执行的代理方法(返回YES进入超链接)
- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange ; 点击富文本中的图片执行的代理法方
通知:
UITextViewTextDidBeginEditingNotification; 开始编辑触发
UITextViewTextDidChangeNotification; 文本内容发生改变触发
UITextViewTextDidEndEditingNotification; 结束编辑触发
and the text view can handle the input in an application-specific way. You can specify attributes, such as font, color, and alignment, that apply to all text in a text view.
大概意思为:UITextView可以编辑多行文本,当UITextView成为第一响应者的时候(进入编辑模式弹出键盘)可以编辑文本。结束编辑的时候可以可以根据自己所设定的特定的文本方式处理响应的文本(包括字体,大小,对其方式,颜色....)
属性:
text:文本
font:字体
textColor:字体颜色
textAlignment:对齐方式 (默认向左对齐)
selectedRange:选择范围(有两个属性location:光标的位置 length:选中的文本的长度)
editable:是否允许编辑(默认是YES允许编辑)
selectable:是否允许选择(默认允许 ios7加入)
dataDetectorTypes:数据检测类型(取值为:UIDataDetectorTypes一共有6种类型:UIDataDetectorTypePhoneNumber:电话文本链接;UIDataDetectorTypeLink:URL链接;UIDataDetectorTypeAddress:地址链接;UIDataDetectorTypeCalendarEvent:日历类型链接;UIDataDetectorTypeNone:没有类型;UIDataDetectorTypeAll:所有类型)只有在不能编辑的情况下这些才能被识别
allowsEditingTextAttributes:允许编辑富文本(默认不允许iOS6加入)
attributedText:富文本
typingAttributes:富文本格式
inputView:输入视图(效果可参考UITextfield)
inputAccessoryView:输入辅助视图 (效果可参考UITextfield)
clearsOnInsertion:是否能修改之前的文本(默认为不能)
textContainer:文本容器(一个矩形区域用于存放已经进行了排版并设置好属性的文字 iOS7加入)
textContainerInset:文本视图的缩进范围(及文本区域的布局iOS7加入)
layoutManager:管理NSTextStorage其中的文字内容的排版布局 (iOS7加入)
textStorage:保存并管理UITextView要展示的文字内容(是NSMutableAttributedString的一个子类iOS7加入)
linkTextAttributes:链接文本的属性(iOS7 加入)
方法:
- (void)scrollRangeToVisible:(NSRange)range;滚动TextView使其显示指定区域的文字
- (instancetype)initWithFrame:(CGRect)frame textContainer:(nullable NSTextContainer *)textContainer ;重新指定文本容器视图的位置内容(iOS7加入)
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder ;反归档
代理:
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView; 是否允许textview进入编辑状态
- (BOOL)textViewShouldEndEditing:(UITextView *)textView; 是否允许textview结束编辑状态
- (void)textViewDidBeginEditing:(UITextView *)textView; textview进入编辑状态后执行的方法(成为第一响应者)
- (void)textViewDidEndEditing:(UITextView *)textView; textview结束编辑状态执行的方法(取消第一响应者)
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text; 是否响应改变当前文本(默认可以该改变,及当前输入的文本有效)
- (void)textViewDidChange:(UITextView *)textView; textview的文本内容发生改变的时候执行的方法
- (void)textViewDidChangeSelection:(UITextView *)textView; 焦点发生改变执行的方法
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange; 是否能够给textview添加超链接及点击超链接执行的代理方法(返回YES进入超链接)
- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange ; 点击富文本中的图片执行的代理法方
通知:
UITextViewTextDidBeginEditingNotification; 开始编辑触发
UITextViewTextDidChangeNotification; 文本内容发生改变触发
UITextViewTextDidEndEditingNotification; 结束编辑触发
相关文章推荐
- 扣丁学堂笔记第02天UI布局
- java 打印对象的属性和值ToStringBuilder.reflectionToString
- IOS动画中的枚举UIViewAnimationOptions
- java 遍历request中的所有表单数据
- 用while(true)和continue、break来实现在一个大循环里switch
- iOS:SVN出错 Description : The working copy is locked due to a previous error.
- hdu-1005 Number Sequence
- CUBRID学习笔记 42 Hierarchical QuerySQL层级查询
- Phyre LCUE with YEBIS cause issues about GS
- require用法及源码解析
- IOS控件学习之UI ScrollView(6)
- 怎么去除MIUI7中日历的广告(超简单)
- 分享修改Wke源代码后重新封装成Duilib控件的代码
- UIView相关Updating constraints、Layout、Display一些知识
- CALayer & UIView 关系浅析
- STM32 + UCGUI+外扩NAND FLASH 中文字库支持方法
- ora-00054:resource busy and acquire with nowait specified解决方法
- UISearchBar限制输入字数以及输入到最大限值以后不能删除
- HDU-1159 Common Subsequence
- UI控件--ImageView和ImageButton