UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 30, 300, 200)];
textView.delegate = self;
textView.tag = 1;
//是否滚动
textView.scrollEnabled = YES;
textView.font = [UIFont systemFontOfSize:30];
textView.layer.borderWidth = 10;//边框框度
[self.window addSubview:textView];
//添加手势
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
[tap addTarget:self action:@selector(hideView)];
- (void)hideView
{
UITextView *view = (UITextView *)[self.window viewWithTag:1];
NSLog(@"%@", view.text);
//以下三种都可以隐藏键盘
// [self.window endEditing:YES];
[view endEditing:YES];
// [view resignFirstResponder];
}
—#pragma mark - UITextViewDelegate
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
return YES;
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSLog(@"正在输入");
if ([text isEqualToString:@"f"])
{
return NO;
}
return YES;
}