Pregunta

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.

¿Fue útil?

Solución

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.

Otros consejos

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 :)

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

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top