iOS: Determine if device language is Right to Left (RTL)

前端 未结 11 1862
后悔当初
后悔当初 2020-12-04 23:20

Is there a way to easily determine if the language the device is set to is right to left (RTL)?

11条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 00:16

    if ([[UIDevice currentDevice].systemVersion floatValue] >= 9.0) {
        if ([UIView userInterfaceLayoutDirectionForSemanticContentAttribute:self.view.semanticContentAttribute] == UIUserInterfaceLayoutDirectionRightToLeft) {
            NSLog(@"Right to left");
        }
        else{
            NSLog(@"left to Right");
        }
    } else {
        /* Use the previous technique */
        //Work for earlier ios 6 to ios 10
        if ([NSLocale characterDirectionForLanguage:[[NSLocale preferredLanguages] objectAtIndex:0]] == NSLocaleLanguageDirectionRightToLeft) {
            NSLog(@"Right to left");
        }
        else{
            NSLog(@"left to Right");
        }
    }
    

    must watch Advanced Topics in Internationalization wwdc2014

提交回复
热议问题