UITextView

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];
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容