Change the iOS keyboard layout to emoji?

后端 未结 2 2031
无人及你
无人及你 2020-11-30 06:10

Is it possible to change the keyboard layout to emoji when a UITextField becomes the first responder ? or according to a user action like tapping a UIButton

I know

2条回答
  •  佛祖请我去吃肉
    2020-11-30 06:59

    * UPDATED FOR iOS13 *

    Create a subclass of UITextField like this:

    class EmojiTextField: UITextField {
    
       // required for iOS 13
       override var textInputContextIdentifier: String? { "" } // return non-nil to show the Emoji keyboard ¯\_(ツ)_/¯ 
    
        override var textInputMode: UITextInputMode? {
            for mode in UITextInputMode.activeInputModes {
                if mode.primaryLanguage == "emoji" {
                    return mode
                }
            }
            return nil
        }
    }
    

    In IB select this class as the Custom Class in place of UITextField.

    This causes the keyboard to select emoji keyboard, if available, when the field becomes first responder. The user can, of course, change the keyboard back to anything else at any time, but at least it gives an initial selection of what you want.

    Thanks to blld for his answer here https://stackoverflow.com/a/58537544/1852207.

提交回复
热议问题