0

I would like to replace the UIStatusBar in my app with my own view.

enter image description here

I'm assuming that I need to hide the status bar - is this right?

The problem with hiding the status bar is that the navigation bar moves up to occupy it's original position. How can I add my view and move everything back down 20 px?

enter image description here

Assuming that I don't have to remove the status bar, but instead can just cover it with my view, I then have the problem of the background color. This changes between views, so I would need to mask out the existing status bar text - how do I do this?

Thanks for your help.

theDuncs
  • 4,649
  • 4
  • 39
  • 63
  • follow this [link](http://www.appcoda.com/customize-navigation-status-bar-ios-7/) . hope this will help – Pawan Rai Mar 19 '14 at 18:20

4 Answers4

1

The first step would be to hide the status bar. In iOS 7, you can do this by adding the prefersStatusBarHidden function, like so:

- (BOOL)prefersStatusBarHidden {
    return YES;
}

This will hide the status bar.

To fix the movement issue you mentioned, you need to set the status bar style for the viewController to none (in the interface editor).

Start off by selecting the View Controller in the left side panel:

vc

Head over to the Attributes Inspector on the right side of Xcode, and set Status Bar to none:

ins enter image description here

That's it, now you can add your own view at the top of the screen with your own content :)

Aleksander Azizi
  • 9,829
  • 9
  • 59
  • 87
  • Side note: If you have written your UI objects programatically, you can set the `Status Bar` style to `none` programatically too ofc. – Aleksander Azizi Mar 19 '14 at 18:29
  • The UINavigationBar still start at y=0. How can I move this down to y=20 so that I can insert my view above the navigation bar? – theDuncs Mar 20 '14 at 09:55
  • You can disable auto layout and set the navBar's `y` to 20 like so: `[navBar setFrame:CGRectMake(navBar.frame.x, 20, navBar.frame.width, navBar.frame.height)];`. – Aleksander Azizi Mar 24 '14 at 14:38
1

Your approach is correct with a little tweak with self.view's frame.

Add below method to your viewController,

-(void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    self.view.frame =CGRectMake(0, 20, 320, [UIScreen mainScreen].bounds.size.height);
}

Above method moves your view by 20 pixels down.

santhu
  • 4,796
  • 1
  • 21
  • 29
  • I don't want to move the whole screen down - just the navigation bar. And I can do that by using self.navigationController.navigationBar instead of self.view. Thank you! – theDuncs Mar 20 '14 at 10:06
0

To hide the status bar completely in iOS7, set "View controller-based status bar appearance" to NO in Info.plist, and [[UIApplication sharedApplication] setStatusBarHidden:YES]; in application:didFinishLaunchingWithOptions

Audun Kjelstrup
  • 1,430
  • 8
  • 13
0

I think you are using autolayout. So for doing that just place all of your views inside another view and in delta y put 20px for ios6/7. and don't forget to follow Audun Kjelstrup's step. Hope it will solve your problem.

if-else-switch
  • 977
  • 1
  • 7
  • 24