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];
}
相关新闻>>
- 发表评论
-
- 最新评论 进入详细评论页>>
今日头条
更多>>您可能感兴趣的文章
- ios 时间定时器 NSTimer应用demo
- iPhone开发 调用阿asp.net程序的webservice
- ios 关于UITableView UITableViewCellAccessoryCheckmark 混乱的
- 深入理解iPhone静态库(手把手教你iphone开发
- iPhone开发 文件的增加删除查询
- (iOS-iap防护)验证用户付费收据,拒绝iap
- Cocoa Core Competencies 的Object creation 和IOS面试题示例
- iphone开发基础三和c语言混编
- iOS文件存磁盘的设想
- iphone-使用TextField及关闭键盘(useing TextField for in