iOS - UI - UITextView

时间:2023-03-08 17:58:12

1、UITextView

//因为继承于UIScrollView 拥有scrollView的所有属性和方法

//placeholder只有UITextField有,UITextView是没有的。(提示文字)

//多行文本框

UITextView * textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 40, self.view.bounds.size.width - 40, 100)];

//设置输入文字

textView.text = @"解放了肯定;

//设置字体

textView.font = [UIFont systemFontOfSize:25];

//设置颜色

textView.textColor = [UIColor redColor];

//设置对齐方式

textView.textAlignment = NSTextAlignmentLeft;

//是否允许编辑

textView.editable = YES;

//设置代理方法

textView.delegate = self;

//inputView(自定义键盘) 可以只设置高度,键盘默认高度216.

2、UITextView 代理

//是否允许开始编辑方法

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {}

//是否允许结束编辑方法

- (BOOL)textViewShouldEndEditing:(UITextView *)textView {}

//已经开始编辑

- (void)textViewDidBeginEditing:(UITextView *)textView {}

//已经结束编辑

- (void)textViewDidEndEditing:(UITextView *)textView {}

//是否允许文本框文字改变

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

//监测文本变化

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

NSLog(@"%@",textView.text);

}