IOS6 控件专辑(2)
//==============================================================================
#pragma mark - UITextView Delegate Methods
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if ([text isEqualToString:@"\n"])
{
[textView resignFirstResponder];
return NO;
}
return YES;
}
这样无论你是使用电脑键盘上的回车键还是使用弹出键盘里的return键都可以达到退出键盘的效果。
(3)还有你也可以自定义其他加载键盘上面用来退出,比如在弹出的键盘上面加一个view来放置退出键盘的Done按钮。
代码如下:
{
UIToolbar * topView = [[UIToolbar alloc]initWithFrame:CGRectMake(0,0,320, 30)];
[topView setBarStyle:UIBarStyleBlack];
UIBarButtonItem * helloButton = [[UIBarButtonItem alloc]initWithTitle:@"Hello" style:UIBarButtonItemStyleBordered
target:self action:nil];
UIBarButtonItem * btnSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:self action:nil];
UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone www.2cto.com
target:self action:@selector(dismissKeyBoard)];
NSArray * buttonsArray =@[helloButton, btnSpace, doneButton];
[topView setItems:buttonsArray];
[tvTextView setInputAccessoryView:topView];
}
-(void)dismissKeyBoard
{
[tvTextView resignFirstResponder];
}
相关新闻>>
- 发表评论
-
- 最新评论 更多>>