UITextView头文件学习

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 selectable NS_AVAILABLE_IOS(7_0);   是否可选中

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

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


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

@property(null_resettable,copy) NSAttributedString *attributedText NS_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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值