Reputation: 4843
I would like to replace the UIStatusBar in my app with my own view.
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?
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.
Upvotes: 0
Views: 430
Reputation: 9877
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:
Head over to the Attributes Inspector on the right side of Xcode, and set Status Bar
to none
:
That's it, now you can add your own view at the top of the screen with your own content :)
Upvotes: 1
Reputation: 4792
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.
Upvotes: 1
Reputation: 977
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.
Upvotes: 0
Reputation: 1430
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
Upvotes: 0