UIKeyboardTypeNamePhonePad-显示选项 [英] UIKeyboardTypeNamePhonePad - Display options

查看:122
本文介绍了UIKeyboardTypeNamePhonePad-显示选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用名称电话键盘"类型(UIKeyboardTypeNamePhonePad),但在选择文本字段时首先显示数字键盘.

I need to use the, Name Phone Keyboard type (UIKeyboardTypeNamePhonePad) but having the number pad appear first when the text field is selected.

我需要输入

123- 657- 450b- 123a

123 - 657 - 450b - 123a

我总是需要先输入一个数字,但偶尔也要输入一个A/B.

I always need input a number first, but occasionally either a A / B at the end.

推荐答案

您可以尝试在字符串大小的函数中更改键盘类型:

You can try to change keyboard type in function of the size of the string:

  • 实施委托UITextFieldDelegate

然后设置defaut文本字段键盘;

Then set defaut textfield keyboard;

[textField setKeyboardType:UIKeyboardTypeNumberPad];
[textField setDelegate:self];

然后按照以下方法,在文本大小等于3时更改键盘:

Then in the following method, change the keyboard when text size equals 3:

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if([[textField text] length] > 3)
    {
        [textField setKeyboardType:UIKeyboardTypeDefault];
        [textField reloadInputViews];
    }
    return YES;
}

另一种解决方案是添加一个附件查看按钮(您可以手动更改键盘):

Another solution is to add an accessory view button (you can change of keyboard manually):

- (void)viewDidLoad
{
    [super viewDidLoad];

    textField.keyboardType = UIKeyboardTypeNumberPad;
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button setFrame:CGRectMake(0, 0, 50, 50)];
    [button addTarget:self action:@selector(changeKeyboard) forControlEvents:UIControlEventTouchDown];
    textField.inputAccessoryView = button;
}

-(void)changeKeyboard
{
    if([textField keyboardType] == UIKeyboardTypeNumberPad)
    {
        textField.keyboardType = UIKeyboardAppearanceDefault;
    }
    else
    {
        textField.keyboardType = UIKeyboardTypeNumberPad;
    }
    [textField reloadInputViews];
}

这篇关于UIKeyboardTypeNamePhonePad-显示选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆