UITextView
UITextFiled&UITextView .UITextView
//UITextView:文本編輯控件
UITextView *textView= [[UITextView alloc] init];
//默認YES
textView.scrollEnabled=YES;
//設置文本顏色
textView.textColor= [UIColor yellowColor];
//設置容器背景顏色
textView1.backgroundColor= [UIColoror angeColor];
//換行\(zhòng)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];
//定寬動態(tài)高度或者定高度動態(tài)寬度(要注意屏幕寬度與內(nèi)容的寬度,換行\(zhòng)n)
//根據(jù)最長的那一行進行適配寬度
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? == 已經(jīng)開始編輯觸發(fā)的方法每一次鍵盤彈起首先會觸發(fā)的方法,一次編輯過程中只觸發(fā)一次;
- (void)textViewDidBeginEditing:(UITextView*)textView {
??? NSLog(@"textViewDidBeginEditing");
?}
#pragma mark? == 文本改變的時候觸發(fā)的方法,多次調(diào)用
- (void)textViewDidChange:(UITextView*)textView {
?? NSLog(@"textViewDidChange");
}
#pragma mark == 光標移動就觸發(fā)
- (void)textViewDidChangeSelection:(UITextView*)textView {
NSLog(@"textViewDidChangeSelection");
}
#pragma mark == 結(jié)束編輯時候得到觸發(fā)時間
- (void)textViewDidEndEditing:(UITextView*)textView {
?? NSLog(@"textViewDidEndEditing");
}
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
//讓鍵盤下落
//告訴當前view編輯已經(jīng)結(jié)束了
//[self.view endEditing:YES];
//取消第一響應者
[textView resignFirstResponder];
}