UITextView 基础篇
来源:互联网 发布:mac 硬解 h265 编辑:程序博客网 时间:2024/06/07 08:15
苹果对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; 结束编辑触发
- UITextView 基础篇
- swift基础篇:iOS控件大拌菜:UILable UIButton UITextView
- ios基础控件之UITextView
- iOS开发基础-UITextView&UITextField
- Swift基础(十七)UITextView
- UITextView
- UITextView
- UITextView
- UITextView
- UITextView
- UITextView
- UITextView
- UITextView
- UITextView
- UITextView
- UITextView
- UITextView
- UITextView
- js与jsp的执行顺序
- PHP之简单MVC
- Android 颜色渲染(一) 颜色选择器 ColorPickerDialog剖析
- [从头学数学] 第139节 二次根式 小结与复习题
- Hdu 5636 Shortest Path【最短路+暴力】
- UITextView 基础篇
- 简单的dialog使用。。
- Android Service、Activity、BroadcastReceiver简单使用
- MySQL5.5从零开始学(2013-12-18 16:22:52)
- UITextField 限制用户输入小数点后位数的方法
- java布局FlowLayout
- 关于mac android studio 与svn 解除关联后 无法再次share (Subversion) 的解决办法
- “反射”的心路历程
- BOM