UIKeyboardTypeNumberPad without a done button(没有完成按钮的 UIKeyboardTypeNumberPad)
问题描述
我们如何实现 UIKeyboardTypeNumberPad 以便它有一个完成"按钮?默认情况下它没有.
How can we implement UIKeyboardTypeNumberPad so that it will have a 'done' button? By default it does not have one.
推荐答案
如果我没记错,那么您想问一下如何在 UIKeyboardTypeNumberPad 的键盘上添加自定义完成"按钮.在这种情况下,这可能会有所帮助.在.h 中声明一个UIButton *doneButton 并将以下代码添加到.m 文件中
If I am not wrong then You want to ask as to how to add a custom "Done" button to keyboard for UIKeyboardTypeNumberPad . In that case this might be helpful. Declare a UIButton *doneButton in.h and add the following code to .m file
- (void)addButtonToKeyboard {
// create custom button
if (doneButton == nil) {
doneButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 163, 106, 53)];
}
else {
[doneButton setHidden:NO];
}
[doneButton addTarget:self action:@selector(doneButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
// locate keyboard view
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard = nil;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard found, add the button
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
[keyboard addSubview:doneButton];
} else {
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
[keyboard addSubview:doneButton];
}
}
}
- (void)doneButtonClicked:(id)Sender {
//Write your code whatever you want to do on done button tap
//Removing keyboard or something else
}
我在我的应用程序中使用了相同的按钮,因此调整了按钮的框架,因此您可以在需要在键盘上显示完成按钮时调用 [self addButtonToKeyboard ].UIKeyboardTypeNumberPad 没有完成按钮.
I am using the same in my application and the button's frame are thus adjusted, You can thus call [self addButtonToKeyboard ] whenever you need to show up the done button over the keyboard. UIKeyboardTypeNumberPad has no Done button otherwise.
这篇关于没有完成按钮的 UIKeyboardTypeNumberPad的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:没有完成按钮的 UIKeyboardTypeNumberPad


- Android viewpager检测滑动超出范围 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01