3

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

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

4

1 回答 1

3

这很简单,你可以这样做:

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

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

如果您需要收到有关更改的通知,请将您的控制器添加为观察者UITextInputCurrentInputModeDidChangeNotification

于 2012-09-05T11:42:10.160 回答