iOS 9 disable support for right-to-left language

做~自己de王妃 提交于 2019-11-30 08:25:24

Edit: The following code may cause unexpected behavior as @wakachamo pointed out. So, please watch out for issues e.g. Interactive pop gesture doesn't work, alertviews don't show, etc. Its better to follow the instruction provided by @wakachamo if this doesn't work for you

Add this to app delegate didFinishLaunchingWithOptions method.

[[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];

Also add guard to support earlier version so that the property doesn't cause any crash.

if([[[UIView alloc] init] respondsToSelector:@selector(setSemanticContentAttribute:)]) {
        [[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
    }

[[UIView alloc] init] instead of [UIView appearance] because respondsToSelector is not currently working with [UIView appearance] for setSemanticContentAttribute. You can also add iOS 9 Check

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0")) {
        [[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
    }

i found the correct way from Apple Developer Forums

here iOS 9 beta - UIAlertController is not working

just add this code to make alertview work with it

 if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0")) {
            [[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];

    [[UIView appearanceWhenContainedIn:[UIAlertController class], nil] setSemanticContentAttribute:UISemanticContentAttributeUnspecified];
    [[UIView appearanceWhenContainedIn:[UIAlertView class], nil] setSemanticContentAttribute:UISemanticContentAttributeUnspecified];



}

I know its too late to answer. But I have figured it out (Only the navigation bar issue).

The answer is adapted from @Kamran Kan. Thanks @Kamran.

Jus replace the UIView with UINavigationBar in @Kamran's answer. then the code will be as follows.

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0")) {
    [[UINavigationBar appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
}

Since it is only effect the UINavigationBar, the other controls won't effect. So the UIAlertView is working fine...

There is no easy way. It's recommended that you migrate to standard API as much as possible long-term.

Another approach is to set the semanticContentAttribute of all the affected views to UISemanticContentAttributeForceLeftToRight, but this is just as feasible as setting all your constraints to use Left/Right instead of Leading/Trailing. In addition to this, you'll also have to gate these calls around an availability check if you're targeting iOS <9.

SWIFT 2 Code

if #available(iOS 9.0, *) {
     myView.semanticContentAttribute = .ForceLeftToRight
}

For SWIFT 3

if #available(iOS 10.0, *) {
     UIView.appearance().semanticContentAttribute = .forceLeftToRight
}
Sedat Y

Use Storyboard and choose for each specific view controllers

Semantic->Force Left-to-Right.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!