UITextView
UITextFiled&UITextView .UITextView
//UITextView:文本編輯控件
UITextView *textView= [[UITextView alloc] init];
//默認(rèn)YES
textView.scrollEnabled=YES;
//設(shè)置文本顏色
textView.textColor= [UIColor yellowColor];
//設(shè)置容器背景顏色
textView1.backgroundColor= [UIColoror angeColor];
//換行\(zhòng)n
textView.text=@"來(lái)段代碼\n\n繼承與scrollViewUITextView:\n文本編輯控件UITextView *textView\n = [[UITextView alloc]i\nnitWithFrame:\nCGRectMake(0, 90, [[UIScreen mainScreen]bounds].size.width, 400)];來(lái)段代碼\n\n繼承與scrollViewUITextView:\n文本編輯控件UITextView *textView\n = [[UITextView alloc]initWithFrame:CGRectMake(0, 90, [[UIScreen mainScreen]bounds].size.width, 400)]來(lái)段代碼\n\n繼承與scrollViewUITextView:\n文本編輯控件UITextView *textView \n= [[UITextView alloc]initWithFrame:CGRectMake(0, 90, [[UIScreen mainScreen]bounds].size.width, 400)]來(lái)段代碼\n\n繼承與scrollViewUITextView:\n文本編輯控件UITextView *textView \n= [[UITextView alloc]initWithFrame:CGRectMake(0, 90, [[UIScreen mainScreen]bounds].size.width, 400)]來(lái)段代碼\n\n繼承與scrollViewUITextView:\n文本編輯控件UITextView *textView \n= [[UITextView alloc]initWithFrame:CGRectMake(0, 90, [[UIScreen mainScreen]bounds].size.width, 400)]來(lái)段代碼\n\n繼承與scrollViewUITextView:\n文本編輯控件UITextView *textView \n= [[UITextView alloc]initWithFrame:CGRectMake(0, 90, [[UIScreen mainScreen]bounds].size.width, 400)]";
//如果設(shè)置了這個(gè)字體大小的話(huà)下面的字體自適應(yīng)大小是沒(méi)有作用的
textView.font= [UIFont fontWithName:@"Arial" size:5.0];
//設(shè)置自動(dòng)大寫(xiě)方式
//textView.autocapitalizationType = YES;
//文本大小自適應(yīng)
//textView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[textView sizeToFit];
//定寬動(dòng)態(tài)高度或者定高度動(dòng)態(tài)寬度(要注意屏幕寬度與內(nèi)容的寬度,換行\(zhòng)n)
//根據(jù)最長(zhǎng)的那一行進(jì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? == 已經(jīng)開(kāi)始編輯觸發(fā)的方法每一次鍵盤(pán)彈起首先會(huì)觸發(fā)的方法项阴,一次編輯過(guò)程中只觸發(fā)一次;
- (void)textViewDidBeginEditing:(UITextView*)textView {
??? NSLog(@"textViewDidBeginEditing");
?}
#pragma mark? == 文本改變的時(shí)候觸發(fā)的方法俺亮,多次調(diào)用
- (void)textViewDidChange:(UITextView*)textView {
?? NSLog(@"textViewDidChange");
}
#pragma mark == 光標(biāo)移動(dòng)就觸發(fā)
- (void)textViewDidChangeSelection:(UITextView*)textView {
NSLog(@"textViewDidChangeSelection");
}
#pragma mark == 結(jié)束編輯時(shí)候得到觸發(fā)時(shí)間
- (void)textViewDidEndEditing:(UITextView*)textView {
?? NSLog(@"textViewDidEndEditing");
}
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
//讓鍵盤(pán)下落
//告訴當(dāng)前view編輯已經(jīng)結(jié)束了
//[self.view endEditing:YES];
//取消第一響應(yīng)者
[textView resignFirstResponder];
}