Earlier, I was using iOS 6.1 for my project. Recently I have switched to iOS 7. For, a lot of changes I knew, I updated my code.. But I have observed a strange behavior. My view on every screen gets hidden below navigation bar. Repositioning view solves the problem for iOS7, but creates problems for older iOS versions.
Can anyone explain me, what is the reason and why does it happen?? What has been changed in iOS 7 that's causing this problem??
Any help would be appreciated..
Try navigationBar.translucent = NO;, It is YES by default in iOS7.
It is also good to take a look on this part of UINavigationBar documentation:
New behavior on iOS 7. Default is YES. You may force an opaque
background by setting the property to NO. If the navigation bar has a
custom background image, the default is inferred from the alpha values
of the image—YES if it has any pixel with alpha < 1.0 If you send
setTranslucent:YES to a bar with an opaque custom background image it
will apply a system opacity less than 1.0 to the image. If you send
setTranslucent:NO to a bar with a translucent custom background image
it will provide an opaque background for the image using the bar's
barTintColor if defined, or black for UIBarStyleBlack or white for
UIBarStyleDefault if barTintColor is nil.
Edit:
Setting 'navigationBar.translucent' value causes exception if you run project in devices/simulators having older iOS versions.
So you can add a version check like this:
float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
if (systemVersion >= 7.0)
{
navigationBar.translucent = NO;
}
Another option would be to set:
vc.edgesForExtendedLayout = UIRectEdgeNone;
Swift 3:
vc.edgesForExtendedLayout = []
You can stop your views going under the navigation bar, in your viewController:
self.edgesForExtendedLayout = UIRectEdgeNone;
Swift 3+:
self.edgesForExtendedLayout = []
If you do not need translucent navigation bar in your app you can fix this on iOS7 and iOS6 without code changes.
In storyboard select your navigation controller and then open "Attributes Inspector". Then under "Simulated Metrics" set "Top Bar" to some value but not to "translucent":
Now your views on iOS6 and iOS7 will have the same positioning as before.
Point #7 on this list does the trick. You still have to wrap it in iOS 7-checking code like #null's answer:
float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
if (systemVersion >= 7.0) {
viewController.edgesForExtendedLayout = UIRectEdgeNone;
}
The whole article is useful to those transitioning to iOS 7.
Use this property for your VC, in-order to avoid overlap of ur statusbar with your VC Swift :
self.edgesForExtendedLayout = []
Objective C
self.edgesForExtendedLayout = UIRectEdgeNone;
Look up this key: UIViewControllerBasedStatusBarAppearance.
It's used in your app's info PLIST file and will come up as:
View controller-based status bar appearance
This will allow you to control the status bar's appearance. There's a bunch of API changes for status bars, go have a look in the documentation for new UIViewController methods such as
- (void)prefersStatusBarHidden;
For me the best way for transparent Navigation Bar is to change the shadowImage and backgroundImage of the bar.
navigationController?.navigationBar.isTranslucent = true
navigationController?.navigationBar.backgroundColor = nil
navigationController?.navigationBar.setBackgroundImage(UIImage(named: "navBarBackground")?.resizableImage(withCapInsets: .zero, resizingMode: .stretch), for: .default)
navigationController?.navigationBar.shadowImage = UIImage()
In Swift 2.2, use
self.edgesForExtendedLayout = .None
Related
I have found many links for Status Bar issue in iOS 7 bt none of them helped much.
The issue is my application runs well in iOS6 but when I try to run it on iOS7, I want the iOS7 look and feel.
The status bar gels nicely with a UIViewController like below :
But for UINavigationController it goes black like below :
I managed to change the text-color of the statusBar using the following code in AppDelegate :
if ([[UIView appearance] respondsToSelector:#selector(setTintColor:)]) {
[[UIView appearance] setTintColor:[UIColor whiteColor]];
}
Also, my plist file has the following entry :
View controller-based status bar appearance set to NO
and my AppDelegate has :
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
I want the statusBar to take the Blue color when a NavigationController is loaded.
NOTE : I have used the following code for iOS7 support :
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
self.edgesForExtendedLayout=UIRectEdgeNone;
#endif
Don't know if this caused the issue.
It's hard to find the solution to your problem, but try using this guide, is really good:
http://www.appcoda.com/customize-navigation-status-bar-ios-7/
It works fine if you use different images. One for iOS7 (20px higher) and one for the others and set this image as background for your navBar.
Hope this help :)
There's a good and explained answer here.
Status bar and navigation bar issue in IOS7
and here
iOS 7 - Status bar overlaps the view
UIView of my app appears fine in ios6 but when it comes to ios7 the entire view is distorted. In ios7 the whole view is lifted upwards.
EDIT :
Then I applied this code:
float SystemVersion=[[[UIDevice currentDevice] systemVersion] floatValue];
if(SystemVersion<7.0f)
{
//Currently your app is running in IOS6 or older version. So you need not to do anything.
}
else
{
// Currently your app is running in IOS7. Do the following.
CGRect TempRect;
for(UIView *sub in [[self view] subviews])
{
TempRect=[sub frame];
TempRect.origin.y+=20.0f; //Height of status bar
[sub setFrame:TempRect];
}
}
but still there is no change. How do I resolve this?
Try this way..
IOS & DISPLAY
OR
This..
Status Bar Issue
This way make the your All subviews as +20 pixels i.e.Increase the +20 of y-axis for all views
Set the deleta for the ios 7. so, it will display the good in both ios 6 & 7.
//Give it frame if navigation bar and status bar both displaying on screen
// first check if device have ios 7
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"7.0"))
{
self.view.frame=CGRectMake(0,64,320,self.view.height);
}
try my answer...write that code in ViewdidLoad method..
Status Bar issue
Happy Coding!!!
Please see below note
Using xcode 5,
click on xib,Go to file inspector and change setting as below
Deployment target as ios 7
here,You need to crate two xib view based on view as ios 7 and later and view as ios 6 and earlier and white condition based on xib call
Define below code in .m file
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
if view as IOS 7.0 and later
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"7.0"))
//Here call ios 7 xib
}else{
//Here call ios 6 and earlier xib
}
You have to create two xib for ios6 and ios7.
than You have to check condition if device is of ios7 than call ios7 xib otherwise go for ios6.
I have an iOS app compiled using the 6.1 SDK with some UIBarButtonItems where the TintColor is set programmatically in ViewWillAppear.
UIBarButtonItem leftButton = new UIBarButtonItem(...);
leftButton.TintColor = UIColor.FromRGB(231, 231, 231);
Resulting in this.
I've upgraded my iPhone to 7.0 but I still need to build for the 6.1 SDK for backwards device compatibility (business reasons).
When I build the app using the 6.1 SDK and run it on an iPhone running iOS 7.0, the toolbar looks like this.
Having read through the iOS 7 UI Transition Guide, I tried setting the UIWindow's TintColor to see if this had an effect. It did not.
On interesting thing - on this form, when I display an ActionSheet, after the ActionSheet is dismissed, the background of the Cancel and Save buttons changes from "black" to "white". I'm currently investigating why this happens.
If I can't change the TintColor programmatically under iOS 7.0 I'm thinking of creating custom background images for the buttons, like this.
And use SetBackgroundImage to override the existing background.
Thanks in advance.
Update - 09.24.13
poupou's answer pointed me to the WWDC video (link) which gave me the solution at 8:37 - I need to set the navigation bar's TintColor instead of setting the specific button's TintColor.
NavigationBar.TintColor = UIColor.FromRGB(231, 231, 231);
I tried setting the UIWindow's TintColor to see if this had an effect. It did not.
It should - but if you're setting TintColor on some other UI elements then it will have priority over the one set on the main UIWindow.
There's a whole session of WWDC 2013 (session 214) about TintColor and how it works in iOS7 (that's the one with the Tic Tac Toe sample).
If you need to run/exclude some code specific to an iOS version you can do:
if (UIDevice.CurrentDevice.CheckSystemVersion (7,0)) {
// iOS 7.0 and later
} else {
// iOS 6.1 and earlier
}
Can't hide status bar on view controller on ios 7 device.
Already tried setting through plist file and also in Appcontroller.mm but still i doesn't hide the status bar
[[UIApplication sharedApplication] setStatusBarHidden:YES];//Doesn't help
Go to info.plist and add two attributes if not present. set "Status bar is initially hidden" to YES and set UIViewControllerBasedStatusBarAppearance to NO. This will hide status bar for your app.
That's because iOS 7 has changed the way it deals with the status bar.
Setting UIViewControllerBasedStatusBarAppearance to NO on your app Info.plist should work.
I had the same issue recently. Be sure that you are targeting the correct view controller. Try to hide the status bar in the root view controller. Also, I´m implementing the method (BOOL)prefersStatusBarHidden (doc) in my UIViewControllers to hide the status bar. By using this method, you can forward the preferred configuration to a "child view controller". Also, this method works fine in UIViewControllers presented as modal.
// for ios 7
- (BOOL)prefersStatusBarHidden
{
return YES;
}
// for ios 6
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
For iPad (iOS 7.0) need to put another value at Info.plist file.
UIStatusBarHidden boolean value YES.
I've tried setting the style of the UINavigationbar to be a translucent style in the viewDidLoad method of my controller. But nothing is changed. Why?
I set the property using the standard code like
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
According to Apple documentation:
UIBarStyleBlackTranslucent is deprecated. Use UIBarStyleBlack and set the translucent property to YES instead.
just had the same issue - the apple doc is a little vague - here's the solution
navigationController.navigationBar.barStyle = UIBarStyleBlack;
navigationContoller.navigationBar.translucent = YES;
UIBarStyleBlackTranslucent
Deprecated. Use UIBarStyleBlack and set the translucent property to YES instead.
Available in iPhone OS 2.0 and later.
Declared in UIInterface.h.