您的位置:首页 > 移动开发 > IOS开发

iOS 给键盘上方添加 收回键盘的按钮

2016-11-04 15:54 267 查看
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures"> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">UITextField</span><span style="font-variant-ligatures: no-common-ligatures"> * beiZhuTF;</span></p>
 
UIToolbar * topView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, DeviceWidth, 40)];
[topView setBarStyle:UIBarStyleDefault];
UIBarButtonItem * spaceBtn = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];

UIButton *doneBtn = [UIButton buttonWithType:UIButtonTypeSystem];
[doneBtn setTitle:@"收回键盘" forState:UIControlStateNormal];
doneBtn.frame = CGRectMake(2, 5, 80, 35);
[doneBtn addTarget:self action:@selector(dealKeyboardHide) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *doneBtnItem = [[UIBarButtonItem alloc]initWithCustomView:doneBtn];
NSArray * buttonsArray = [NSArray arrayWithObjects:spaceBtn,doneBtnItem,nil];
[topView setItems:buttonsArray];
 
[beiZhuTF setInputAccessoryView:topView];
[beiZhuTF setAutocorrectionType:UITextAutocorrectionTypeNo];
[beiZhuTF setAutocapitalizationType:UITextAutocapitalizationTypeNone];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: