Question

I am having trouble figuring out how to get the status bar in ios 7 to use the color of my nav bar. I am using UINavigationController in conjunction with the SWRevealController library for the sliding menu nav.

This is how a page looks right now:

enter image description here

I want the status bar to inherit the gray color of the nav bar. How can I do this?

Was it helpful?

Solution

You can modify your project's Info.plist and set 'View controller-based status bar appearance' as NO

In AppDelegate you have to add

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

to AppDelegates didFinishLaunchingWithOptions Method.

Hopefully it will works for you.

OTHER TIPS

In iOS 7 navigation bar image height is 64 pixels. You need to create two images, one for navigation bar for iOS 7 with height of 64 pixels and another for iOS 6 or less with height of 44 pixels

Then use this code

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)?YES:NO) {
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"your 64 image"] forBarMetrics:UIBarMetricsDefault];
 } 
else 
{
 [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"your 44 image"] forBarMetrics:UIBarMetricsDefault];
}

Make a custom view and set the color of navigation bar to that view, place this view on the place of status bar, and change the color of your status bar to transparent. Happy coding

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)?YES:NO) {
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"newImage.png"] forBarMetrics:UIBarMetricsDefault];
 } 
else 
{
 [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"previousImage.png"] forBarMetrics:UIBarMetricsDefault];
}

Set the navigation bar's delegate to be the current view controller and attach the navigation bar to the top.

class ViewController: UIViewController, UINavigationBarDelegate {

@IBOutlet weak var navigationBar: UINavigationBar!

override func viewDidLoad() {
    navigationBar.delegate = self
}

func positionForBar(bar: UIBarPositioning) -> UIBarPosition {
    return .TopAttached
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top