1. [代码]iOS关于UITextView的基本用法属性和协议 跳至 [1] [全屏预览]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
- (
void
)UI{
//UITextView(使用须遵守UITextViewDelegate协议)
UITextView
*textView = [
UITextView
new
];
//设置是否可以编辑
textView.editable =
YES
;
//设置代理
textView.delegate =
self
;
//设置内容
textView.text = @
"xxxxxxxxxx"
;
//字体颜色
textView.textColor = [
UIColor
cyanColor];
//设置字体
textView.font = [
UIFont
systemFontOfSize:30];
//设置是否可以滚动
//UITextView继承于UIScrollView
textView.scrollEnabled =
NO
;
//UITextView 下得键盘中return 表示换行
[
self
.view addSubview:textView];
//消除影响(iOS7 如果把UIscrollView 加在导航中一般内容会向下走64)
self
.automaticallyAdjustsScrollViewInsets =
NO
;
}
#pragma mark - UITextViewDelegate协议中的方法
//将要进入编辑模式
- (
BOOL
)textViewShouldBeginEditing:(
UITextView
*)textView{
return
YES
;}
//已经进入编辑模式
- (
void
)textViewDidBeginEditing:(
UITextView
*)textView{}
//将要结束/退出编辑模式
- (
BOOL
)textViewShouldEndEditing:(
UITextView
*)textView{
return
YES
;}
//已经结束/退出编辑模式
- (
void
)textViewDidEndEditing:(
UITextView
*)textView{}
//当textView的内容发生改变的时候调用
- (
void
)textViewDidChange:(
UITextView
*)textView{}
//选中textView 或者输入内容的时候调用
- (
void
)textViewDidChangeSelection:(
UITextView
*)textView{}
//从键盘上将要输入到textView 的时候调用
//rangge 光标的位置
//text 将要输入的内容
//返回YES 可以输入到textView中 NO不能
- (
BOOL
)textView:(
UITextView
*)textView shouldChangeTextInRange:(
NSRange
)range replacementText:(
NSString
*)text{
return
YES
;}
|