代码用于在Numberkeypad
中添加完成按钮- (void)keyboardWillShow:(NSNotification *)note {
// create custom button
doneButton = [[UIButton alloc]init];
doneButton.frame = CGRectMake(0, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setTitle:@"Done" forState:UIControlStateNormal];
[doneButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[doneButton addTarget:self action:@selector(done) forControlEvents:UIControlEventTouchUpInside];
if (IS_iOS_7_OR_LATER) {
dispatch_async(dispatch_get_main_queue(), ^{
UIView *keyboardView = [[[[[UIApplication sharedApplication] windows] lastObject] subviews] firstObject];
[doneButton setFrame:CGRectMake(0, keyboardView.frame.size.height - 53, 106, 53)];
[keyboardView addSubview:doneButton];
[keyboardView bringSubviewToFront:doneButton];
[UIView animateWithDuration:[[note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]-.02
delay:.0
options:[[note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]
animations:^{
self.view.frame = CGRectOffset(self.view.frame, 0, 0);
} completion:nil];
});
}else {
// locate keyboard view
dispatch_async(dispatch_get_main_queue(), ^{
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard view found; add the custom button to it
if([[keyboard description] hasPrefix:@"UIKeyboard"] == YES)
[keyboard addSubview:doneButton];
}
});
}
}
我已编写代码在数字键盘中添加完成按钮,它与设备的默认键盘完美配合,如果设备安装了第三方键盘,则会出现问题[快捷键App]是否有办法识别第三方键盘要解决这个问题
提前致谢!
答案 0 :(得分:1)
如果你愿意,我知道一种方式,但你不是说的; 您不需要任何第三方库来使用此方法 你只需创建UIBarButton并向UIToolbar添加按钮,最后只需在实现后添加创建的工具栏
YourNumberTextField.inputAccessoryView = textFieldToolBar;
这是一个代码
UIToolbar* textFieldToolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
textFieldToolBar.barStyle = UIBarStyleBlackTranslucent;
textFieldToolBar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:@"Clear All" style:UIBarButtonItemStyleBordered target:self action:@selector("YourClearButtonFunctionName")],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:@"Ok!" style:UIBarButtonItemStyleDone target:self action:@selector("YourOkButtonFunctionName")],
nil];
[textFieldToolBar sizeToFit];
YourNumberTextField.inputAccessoryView = textFieldToolBar;