By ahmad


2012-07-08 11:24:29 8 Comments

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 that i can change the keyboard layout to one of these

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;

I am wondering if there's a way to do the same with the emoji layout

1 comments

@Dale 2017-06-26 05:51:51

Create a subclass of UITextField like this:

class EmojiTextField: UITextField {

    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.

@inorganik 2017-07-07 20:19:19

yes, this!!!11!

@Fadi Abuzant 2018-02-02 20:21:27

Helpful trick thanks man πŸ‘πŸ»

@Demosthese 2018-07-06 21:27:37

That's just perfect

@Phontaine Judd 2019-08-19 17:10:04

Love it when I'm told I can't do something, but then someone here on SO goes and shows that I CAN do it. This is perfect and exactly what I was looking for. Thanks!

@Andy Bernard 2019-08-21 20:49:31

Can we limit this so the user cannot switch back to anything else? Only getting the Emoji keyboard?

@Dale 2019-08-21 21:25:38

No, that’s not possible as far as I can tell. This method just sets the initial keyboard

@Chris Van Buskirk 2019-09-18 22:14:57

I think this no longer works in iOS 13. Ugh.

Related Questions

Sponsored Content

92 Answered Questions

37 Answered Questions

[SOLVED] Close iOS Keyboard by touching anywhere using Swift

  • 2014-06-09 18:38:10
  • lagoon
  • 321298 View
  • 365 Score
  • 37 Answer
  • Tags:   ios swift uikeyboard

26 Answered Questions

40 Answered Questions

[SOLVED] Move view with keyboard using Swift

34 Answered Questions

[SOLVED] How to change the name of an iOS app?

  • 2008-10-27 03:07:03
  • Robert Gould
  • 447951 View
  • 957 Score
  • 34 Answer
  • Tags:   ios

35 Answered Questions

[SOLVED] iOS - Dismiss keyboard when touching outside of UITextField

6 Answered Questions

1 Answered Questions

[SOLVED] Custom Number Pad For iPad App

1 Answered Questions

UIKeyboardType overridden by default keyboard for language?

1 Answered Questions

[SOLVED] Change UIKeyboardType based on text input

Sponsored Content