2016-03-07 79 views

回答

0

以上iOS7.0

- (void)textFieldDidEndEditing:(UITextField *)textField { 
NSString *primaryLanguageId = textField.textInputMode.primaryLanguage; 
} 

iOS7.0及以下

- (void)textFieldDidEndEditing:(UITextField *)textField { 
NSString *primaryLanguageId = [UITextInputMode currentInputMode].primaryLanguage; 
} 
0

只要您在使用[UITextInputMode currentInputMode].primaryLanguage獲得的launguage代碼字符串,但也必須添加觀察者,因爲如果鍵盤launguage是然後這個觀察者通知語言改變。

Objective-C的

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(changeInputMode:) 
               name:UITextInputCurrentInputModeDidChangeNotification object:nil];} 
} 

//This method prints the currently selected input language (like "en_US" or "de_DE"): 

-(void)changeInputMode:(NSNotification *)notification 
{ 
    NSString *inputMethod = [[UITextInputMode currentInputMode] primaryLanguage]; 
    NSLog(@"inputMethod=%@",inputMethod); 
} 

夫特:

class ViewController: UIViewController 
{ 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     NSNotificationCenter.defaultCenter().addObserver(self, 
                 selector: "changeInputMode:", 
                 name: UITextInputCurrentInputModeDidChangeNotification, object: nil) 
    } 

    func changeInputMode(notification : NSNotification) 
    { 
     let inputMethod = UITextInputMode.currentInputMode().primaryLanguage 
     println("inputMethod: \(inputMethod)") 
    } 


} 
相關問題