iOS 9 disable support for right-to-left language - ios

My iOS app is in Arabic (right-to-left) language only. Prior to iOS 9 the views layout and view animations were all by default left-to-right. So, I had customised the complete app and had reversed the default behaviour e.g. back button in navigation bar was set to be on the right instead of default left.
But now when the app is compiled using latest SDK (Xcode 7 beta 4), everything is the opposite of what I need.
Is there any simple way to force the app to show views and behave like iOS 8 and 7?
I searched and found a solution but it involves changing the constraints(Uncheck the "Respect language direction") for all views. But this is not a feasible solution in large projects.
This is a screenshot after compiling with Xcode 7 beta 4.
and this is a screenshot when compiled with Xcode 6.

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
}

Use Storyboard and choose for each specific view controllers
Semantic->Force Left-to-Right.

Related

autolayout center X constraints flips in RTL in iOS 9

I have 2 buttons in a view and following is the screen for RTL works fine:
And in RTL it flips both and shows like this :
I am unable to stop flipping by unchecking respect language direction
I have added Constraint like this :
Its working fine on iOS 8 I want to stop them automatic flipping for iOS 9, Any guidance ?
Set the semantic content attribute of the superview to Force Left-To-Right.
or You can use this in appDelegate,
-(BOOL) isGreaterIOSVersion:(NSString*) version
{
NSString *systemVersion = [[UIDevice currentDevice] systemVersion];
if ([systemVersion compare:version options:NSNumericSearch] != NSOrderedAscending) {
return YES;
}
return NO;
}
add below code to in didFinishLaunchingWithOptions function
if([self isGreaterIOSVersion:9.0]) {
[[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
}
it will remove RTL

Views in iOS7 moved above Navigation bar but work fine in iOS6

I am unable to get the UISearchBar to display fine on iOS7. I cannot use AutoLayout as I must support the app for older versions of iOS prior to 6 also. I tried setting the container view's frame if the iOS is of version 7 and above but it does not work. I also tried topLayOutGuide length and other tips mentioned in other SO posts but I could not succeed. (EDIT:- I am using STORYBOARD)
The only thing I currently have in my code is
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"7.0")) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
Can someone please help me with this issue?
I try to suggest a change to do in the storyboard:
tap on your viewController and on attributes inspector uncheck Under top bars
if this not work try this code:
-(void)viewWillAppear:(BOOL)animated {
NSString *ver = [[UIDevice currentDevice] systemVersion];
int ver_int = [ver intValue];
if (ver_int < 7) {
}
else {
self.navigationController.navigationBar.translucent = NO;
}
}

using xcode 5 interface builder for setting tab bar tint (background) color

I am quite new to ios development and I have the following question.
While designing a tabBar in a storyboard in xcode 5 I realized that I can't set the background color of the tabBar for ios 6.
This seems to relate to the fact that in ios6 the bar backgroundcolor was tintColor and in ios 7 this was changed to barTintColor.
If I change the storyboard "View as" parameter to "iOS 6.1 and Ealier" I see that the background color changes from the right value which I did set up in the attribut editor (Bar Tint) to the standard value of iOS 6.
Of course I can set the value from code but this would be bad for maintainability.
Is there I way how one can define this value for iOS 6 in the xcode 5 interface builder?
UPDATE: Since I don't found a satisfying solution for this problem up to now I use the following workaround.
I set the background color of the tabBar in the attribute inspector to the attributes "Bar Tint" and "Background" from the View.
In my app delegate I use the following code:
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7) {
[tabBar setSelectedImageTintColor:tabBar.tintColor];
tabBar.tintColor = tabBar.backgroundColor;
}
I ran into the same issue.
Unfortunately you will have to preserve the iOS 6 compatibility in code, using something similar to this:
// iOS 6 compatibility
NSString *reqSysVer = #"7.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] == NSOrderedAscending) {
[[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:66.f/255.f green:173.f/255.f blue:179.f/255.f alpha:1.f]];
[[UIBarButtonItem appearance] setTintColor:[UIColor colorWithRed:66.f/255.f green:173.f/255.f blue:179.f/255.f alpha:1.f]];
}
I'm not sure why the 'tint' in InterfaceBuilder does not work, but that isn't on our end.
Note: if you want to support iOS < 5.0 you will have to modify the iOS version check, since the UIAppearance protocol is only available since iOS 5.0

how to set iOS 6/7 Deltas programmatically

I was developing a UISplitView app by using Xcode 4.6 when I left iOS6 I had design:
Now I migrate to new Xcode5 and now I have this design:
UINavigationBar overlaps completelly my UISearchBar...
Leo Natan told me about using a iOS 6/7 Deltas but since I'm creating and adding my UISplitViewControllers programmatically,
this may doesn't work I need to set the iOS 6/7 programmatically but I don't know how, any help I'll appreciate
In iOS 7 there are now extended edges, and that's why navigation bar overlaping the searchbar. You can set self.edgesForExtendedLayout = UIRectEdgeNone; this is UIVewControlelr property.
You can also make checks depending on version of iOS and You can do things depending on current version of iOS in device.
NSString *version = [[UIDevice currentDevice] systemVersion];
int ver = [version intValue];
if (ver < 7){
//iOS 6 work
}
else{
//iOS 7 related work
}
Also, you can use NSFoundationVersionNumber
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
// > iOS7
} else {
// <= iOS6
}
You can create a makro for solve this problem.
it is useful for me.
#define iOS7Delta (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0 ) ? 20 : 0 )
If the view's embedded in a UINavigationController -
simply untick "Translucent" for your root navigation bar.
In storyboard, select Navigation Controller Scene,
next select Navigation Bar and in Attributes Inspector (Utilities - 4 tab)
untick "Translucent"

UITableView background View nil doesn't work in iOS 5

I need to make my grouped UITableView backgroundColor transparent.
So i write following code. That is work in iOS 6. But in iOS 5, it doesn't work.
self.tbView.backgroundView = nil;
How to do that in iOS 5.
Are you setting [self.tbView setBackgroundColor:[UIColor clearColor]];?
If not, you need to add that or you won't get a transparent backgorund color.
You Need to put background Nil code into ViewDidLoad this is working fine in my Code. Hope this Helps you.
[tbl_My_Table setBackgroundView:nil];
[tbl_My_Table setBackgroundView:[[[UIView alloc] init] autorelease]];
I got it answer.
We need to add two lines of codes for both iOS 6 and iOS 5.
Here is codes.
self.tblPreferences.backgroundView = nil;
self.myTable.backgroundColor = [UIColor clearColor];
That is working both iOS 5 and 6.

Resources