1.自定义键盘
```
self.view.inputView:
```
2.退出键盘
```
1> [self resignFristResponer];
2>[self.view endEdting];
```
3.退出自定义键盘
```
self.view.inputView =nil;
//清空自定义键盘,系统视作恢复系统自带键盘
textfield= [[UITextFieldalloc]initWithFrame:CGRectMake(100,100,100,100)];
textfield.backgroundColor= [UIColorredColor];
[self.viewaddSubview:textfield];
UIToolbar* topView = [[UIToolbaralloc]initWithFrame:CGRectMake(0,0,320,30)];
[topViewsetBarStyle:UIBarStyleBlackTranslucent];
//让键盘在右边,创建一个空的按钮
UIBarButtonItem* btnSpace = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpacetarget:selfaction:nil];
UIButton*btn = [UIButtonbuttonWithType:UIButtonTypeCustom];
btn.frame=CGRectMake(2,5,100,25);
[btnsetTitle:@"键盘收起"forState:UIControlStateNormal];
[btnaddTarget:selfaction:@selector(dismissKeyBoard)forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem*doneBtn = [[UIBarButtonItemalloc]initWithCustomView:btn];
NSArray* buttonsArray = [NSArrayarrayWithObjects:btnSpace,doneBtn,nil];
[topViewsetItems:buttonsArray];
[textfieldsetInputAccessoryView:topView];
}
-(void)dismissKeyBoard
{
[textfieldresignFirstResponder];
}
```
网友评论