当 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;
我想知道是否有办法对表情符号布局执行相同的操作?
像这样创建 UITextField 的子类:
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
}
}
在 Interface Builder 中,选择此类作为自定义类来代替 UITextField。
当字段成为第一响应者时,这会导致键盘选择表情符号键盘(如果可用)。当然,用户可以随时将键盘更改回任何其他键盘,但至少它可以提供您想要的初始选择。
谢谢blld https://stackoverflow.com/users/4143698/blld他的回答在这里https://stackoverflow.com/a/58537544/1852207 https://stackoverflow.com/a/58537544/1852207.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)