how to set iOS 6/7 Deltas programmatically - ios

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"

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

iOS 9 disable support for right-to-left language

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.

status bar position is not proper when wkWebview plugin is added in iOS phonegap application

I am developing iOs application using phonegap.
phonegap version : 3.5.0
xcode version : 6.1.1
I have added the "org.apache.cordova.statusbar" plugin for the status bar. My application is working fine on iOs 7 & iOs 8. But for better performance in iOs 8, I have added the "com.telerik.plugins.wkwebview" plugin. After adding this plugin, header part of application is destroy and looking that it is inside status bar. I have also attached image with this question. I have added the following property in my_project-info.plist file:
Status bar is initially hidden : NO
View controller-based status bar appearance : YES
You can solve this issue using following steps
1) Go to your project explorer, click on class folder there is file "MainViewController.m", add code
- (BOOL)prefersStatusBarHidden {
return YES;
}
2) Go to your project explorer, click on Resources folder there is file like "Your_project_name-Info.plist" add here as key View controller-based status bar appearance and value YES.
Find the "- (void)viewWillAppear:(BOOL)animated" method from MainViewController.m file and replace the method with following code.
- (void)viewWillAppear:(BOOL)animated
{
// View defaults to full size. If you want to customize the view's size, or its subviews (e.g. webView),
// you can do so here.
//Lower screen 20px on iOS 7 and iOS 8
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7){
CGRect viewBounds = [self.webView bounds];
viewBounds.origin.y = 20;
viewBounds.size.height = viewBounds.size.height - 20;
self.webView.frame = viewBounds;
}
[super viewWillAppear:animated];
}
This solution has worked for me.

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

Resources