没有完成按钮的 UIKeyboardTypeNumberPad

UIKeyboardTypeNumberPad without a done button(没有完成按钮的 UIKeyboardTypeNumberPad)

本文介绍了没有完成按钮的 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

基础教程推荐