gpt4 book ai didi

iphone - 没有完成按钮的 UIKeyboardTypeNumberPad

转载 作者:技术小花猫 更新时间:2023-10-29 11:15:23 27 4
gpt4 key购买 nike

我们如何实现 UIKeyboardTypeNumberPad 以便它有一个“完成”按钮?默认情况下它没有。

最佳答案

如果我没记错,那么您想询问如何为 UIKeyboardTypeNumberPad 添加自定义“完成”按钮到键盘。在那种情况下,这可能会有所帮助。在.h中声明一个UIButton *doneButton 并在.m文件中添加如下代码

- (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 没有完成按钮。 enter image description here

关于iphone - 没有完成按钮的 UIKeyboardTypeNumberPad,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4824352/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com