1.不能滾動
self.scrollEnabled = NO;
[UIFont systemFontOfSize:30.0f]
[UIFont boldSystemFontOfSize:30.0f]
self.textContainerInset = UIEdgeInsetsMake(TEXTVIEW_TOP_INSET, TEXTVIEW_LEFT_INSET, TEXTVIEW_BOTTOM_INSET,TEXTVIEW_RIGHT_INSET);
[self becomeFirstResponder];
[self setEditable:YES];
7.限制輸入長度
按照這個思路,即 將要生成的文本長度 = 原始文本長度 - 選中文本長度 + 輸入文本長度。再考慮到刪除的情況,我的代碼如下: - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { if ([text isEqualToString:@""] && range.length > 0) { //刪除字符肯定是安全的 return YES; } else { if (textView.text.length - range.length + text.length > MAX_INPUT_LENGTH) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"超出最大可輸入長度" message:nil delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil]; [alert show]; return NO; } else { return YES; } } }
8.不能選中
[self setSelectable:YES];