2017-10-05 60 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

我想要鍵盤上只有十六進制字符啓用,用戶可以清楚地看到他只能輸入十六進制字符,或只有十六進制字符在鍵盤上可見 –