UITextView
UITextFiled&UITextView .UITextView
//UITextView:文本编辑控件
UITextView *textView= [[UITextView alloc] init];
//默认YES
textView.scrollEnabled=YES;
//设置文本颜色
textView.textColor= [UIColor yellowColor];
//设置容器背景颜色
textView1.backgroundColor= [UIColoror angeColor];
//换行\n
textView.text=@"来段代码\n\n继承与scrollViewUITextView:\n文本编辑控件UITextView *textView\n = [[UITextView alloc]i\nnitWithFrame:\nCGRectMake(0, 90, [[UIScreen mainScreen]bounds].size.width, 400)];来段代码\n\n继承与scrollViewUITextView:\n文本编辑控件UITextView *textView\n = [[UITextView alloc]initWithFrame:CGRectMake(0, 90, [[UIScreen mainScreen]bounds].size.width, 400)]来段代码\n\n继承与scrollViewUITextView:\n文本编辑控件UITextView *textView \n= [[UITextView alloc]initWithFrame:CGRectMake(0, 90, [[UIScreen mainScreen]bounds].size.width, 400)]来段代码\n\n继承与scrollViewUITextView:\n文本编辑控件UITextView *textView \n= [[UITextView alloc]initWithFrame:CGRectMake(0, 90, [[UIScreen mainScreen]bounds].size.width, 400)]来段代码\n\n继承与scrollViewUITextView:\n文本编辑控件UITextView *textView \n= [[UITextView alloc]initWithFrame:CGRectMake(0, 90, [[UIScreen mainScreen]bounds].size.width, 400)]来段代码\n\n继承与scrollViewUITextView:\n文本编辑控件UITextView *textView \n= [[UITextView alloc]initWithFrame:CGRectMake(0, 90, [[UIScreen mainScreen]bounds].size.width, 400)]";
//如果设置了这个字体大小的话下面的字体自适应大小是没有作用的
textView.font= [UIFont fontWithName:@"Arial" size:5.0];
//设置自动大写方式
//textView.autocapitalizationType = YES;
//文本大小自适应
//textView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[textView sizeToFit];
//定宽动态高度或者定高度动态宽度(要注意屏幕宽度与内容的宽度,换行\n)
//根据最长的那一行进行适配宽度
CGSizesize = [textView sizeThatFits:CGSizeMake(MAXFLOAT, 300)];
//[textView sizeThatFits:CGSizeMake([[UIScreen mainScreen]bounds].size.width, MAXFLOAT)];
textView.frame=CGRectMake(0, 80, size.width, 100);
textView.delegate=self;
[self.view addSubview:textView];
#pragma mark == 已经开始编辑触发的方法每一次键盘弹起首先会触发的方法,一次编辑过程中只触发一次;
- (void)textViewDidBeginEditing:(UITextView*)textView {
NSLog(@"textViewDidBeginEditing");
}
#pragma mark == 文本改变的时候触发的方法,多次调用
- (void)textViewDidChange:(UITextView*)textView {
NSLog(@"textViewDidChange");
}
#pragma mark == 光标移动就触发
- (void)textViewDidChangeSelection:(UITextView*)textView {
NSLog(@"textViewDidChangeSelection");
}
#pragma mark == 结束编辑时候得到触发时间
- (void)textViewDidEndEditing:(UITextView*)textView {
NSLog(@"textViewDidEndEditing");
}
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
//让键盘下落
//告诉当前view编辑已经结束了
//[self.view endEditing:YES];
//取消第一响应者
[textView resignFirstResponder];
}