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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容