1.键盘回收
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
//回车键盘回收
if ([@" " isEqualToString:text] == YES)
{
[textView resignFirstResponder];
return NO;
}
}
2.模拟placeholder
①建两个textView:1.myTextView (实际用的),背景色设置透明;2.placeHolderTextView,它应置于myTextView下边。
②实现textView的代理:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSLog(@"%@",text);
//回车键盘回收
if ([@" " isEqualToString:text] == YES)
{
[textView resignFirstResponder];
return NO;
}
/*****模拟placeholder****/
if (![text isEqualToString:@""])
{
_placeHolderTextView.hidden = YES;
[_myTextView setBackgroundColor:[UIColor whiteColor]];
}
if ([text isEqualToString:@""] && range.location == 0 && range.length == 1)
{
_placeHolderTextView.hidden = NO;
[_myTextView setBackgroundColor:[UIColor clearColor]];
}
/*****模拟placeholder****/
/*****限制输入字符个数****/
NSString *string = [textView.text stringByReplacingCharactersInRange:range withString:text];
NSLog(@"%@",string);
if (string.length > MAX_FEEDBACK_NUMBER)
{
textView.text = [string substringToIndex:MAX_FEEDBACK_NUMBER];
return NO;
}
return YES;
/*****限制输入字符个数****/
}