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
基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01