OGeek|极客世界-中国程序员成长平台

标题: iphone - 如何使用 UITextInputMode [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 16:05
标题: iphone - 如何使用 UITextInputMode

我需要创建一个检测键盘输入语言的方法。例如,当键盘语言是法语时会做某事,而英语什么时候会做其他事情

我在网上搜索,找到了UITextInputMode,但是我不知道怎么用,如果你能帮助我,我将不胜感激。谢谢



Best Answer-推荐答案


很简单,你可以这样做:

UITextInputMode *textInput = [UITextInputMode currentInputMode];
NSString *primaryLanguage = textInput.primaryLanguage;
NSLog(@"Current text input is: %@", primaryLanguage);

如 Apple 文档中所述,“此属性的值是 BCP 47 语言代码,例如“es”、“en-US”或“fr-CA””。 p>

如果您需要收到有关更改的通知,请将您的 Controller 添加为 UITextInputCurrentInputModeDidChangeNotification

的观察者

关于iphone - 如何使用 UITextInputMode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12280606/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4