2017-10-05 27 views
0

是否有任何选项在swift中使用扩展名或其他方式使用HEX(0-9,A,B,C,D,E,F)值创建新的UIKeyboardType?我想要的键盘,才十六进制字符就可以实现,用户可以清楚地看到,他只能输入十六进制字符,或仅十六进制字符是键盘上可见如何仅为十六进制输入制作UIKeyboardType?

+1

只是让你自己的UIVIew包含用于输入十六进制代码的按钮,并将它传递给UITextField的inputView属性。 –

+0

这很好我会尝试这 –

回答

0

第一种情况,下面还有我们提到给出的键盘类型可以设置textField.keyboardType属性并使用它。

public enum UIKeyboardType : Int {  
    case `default` // Default type for the current input method.  
    case asciiCapable // Displays a keyboard which can enter ASCII characters  
    case numbersAndPunctuation // Numbers and assorted punctuation.  
    case URL // A type optimized for URL entry (shows ./.com prominently).  
    case numberPad // A number pad with locale-appropriate digits (0-9, ۰-۹, ०-९, etc.). Suitable for PIN entry.  
    case phonePad // A phone pad (1-9, *, 0, #, with letters under the numbers).  
    case namePhonePad // A type optimized for entering a person's name or phone number. 
    case emailAddress // A type optimized for multiple email address entry (shows space @ . prominently). 
    @available(iOS 4.1, *) 
    case decimalPad // A number pad with a decimal point. 
    @available(iOS 5.0, *) 
    case twitter // A type optimized for twitter text entry (easy access to @ #) 
    @available(iOS 7.0, *) 
    case webSearch // A default keyboard type with URL-oriented addition (shows space . prominently). 
    @available(iOS 10.0, *) 
    case asciiCapableNumberPad // A number pad (0-9) that will always be ASCII digits. 
    public static var alphabet: UIKeyboardType { get } // Deprecated 
} 

第二种情况是,要限制用户不能进入不需要的值(如你只需要1-9和AZ),在这种情况下,你可以使用func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool代表和验证用户输入和输入字符是根据您的要求返回true否则返回false

第三种情况如果可以使用给定的键盘作为用户比可以更好地创建自定义键盘,请参阅此Apple developer reference。和nice tutorial,我也曾经学过。

+0

是的我知道,但我只是想知道这是可能的扩展现有的键盘类型? –

+0

也有创建自定义键盘的方法,但如果您清楚地解释您的需求,它将非常好。 – Buntylm

+0

我想要键盘上只有十六进制字符启用,用户可以清楚地看到他只能输入十六进制字符,或只有十六进制字符在键盘上可见 –

相关问题