改变键盘布局表情符号(change the keyboard layout to emoji)

2019-06-26 03:08发布

是否有可能改变键盘布局为UITextField成为第一个响应者表情符号? 或根据类似攻丝一个UIButton的用户动作

我知道我可以改变键盘布局的其中之一

typedef enum {
UIKeyboardTypeDefault,                // Default type for the current input method.
UIKeyboardTypeASCIICapable,           // Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active
UIKeyboardTypeNumbersAndPunctuation,  // Numbers and assorted punctuation.
UIKeyboardTypeURL,                    // A type optimized for URL entry (shows . / .com prominently).
UIKeyboardTypeNumberPad,              // A number pad (0-9). Suitable for PIN entry.
UIKeyboardTypePhonePad,               // A phone pad (1-9, *, 0, #, with letters under the numbers).
UIKeyboardTypeNamePhonePad,           // A type optimized for entering a person's name or phone number.
UIKeyboardTypeEmailAddress,           // A type optimized for multiple email address entry (shows space @ . prominently).

UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, // Deprecated

} UIKeyboardType;

我想知道是否有一种方法做表情符号布局相同

Answer 1:

创建的UITextField像这样的一个子类:

class EmojiTextField: UITextField {

    override var textInputMode: UITextInputMode? {
        for mode in UITextInputMode.activeInputModes {
            if mode.primaryLanguage == "emoji" {
                return mode
            }
        }
        return nil
    }
}

在IB到位的UITextField的选择这一类的自定义类。

这会导致键盘选择表情符号键盘,如果有的话,当现场成为第一个响应者。 用户当然可以,改回键盘,在任何时候任何东西,但至少它给你想要什么的初始选择。



文章来源: change the keyboard layout to emoji