I have a Navigation Controller with nav bar. The issue I have is I can set the status bar to white, but once the nav bar animates onto the page, they return to black. I've tried using the following with no success:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[UIApplication sharedApplication.setStatusBarStyle = UIStatusBarStyleLightContent;
-(UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
and still the time, batter status, etc return to black. I would be fine with making it completely disappear if no one can figure out what I'm doing wrong lol. Thanks in advance.
Starting with iOS 8 the status bar gets its color from the view controller of the top most view that is currently visible. Try setting the following on the Navigation Controller (assuming the UINavigationController view is the top most view):
<navController>.navigationBar.barStyle = UIBarStyleBlack;
If that doesn't work try adding the override to the top level UIViewController as you did (make sure its the primary view controller contained in your UIWindow.. assuming this is not your UINavigationController..]):
-(UIStatusBarStyle) preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
Also:
In the .plist file for your project, make sure the "View controller-based status bar appearance" is set to YES.
Alternative
If you want your
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
command to have an effect set "View controller-based status bar appearance" to NO in your .plist file. Please note though that view controller based status bars are the wave of the future and some third party libraries (like PSPDFKit) now require this option to be enabled.
Hiding Status Bar
If you want to hide the status bar you can try by setting "View controller-based status bar appearance" to NO in your .plist file. Then add the following code to viewWillAppear of your main view controller:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
Related
I have a UIViewController embedded in a popover. This controller has two subviews, a UINavigationBar and a UITableView. I try to implement the new search API (as SearchDisplayControlled is deprecated in iOS8).
When I click in the search bar (displaying two scopes), everything is all right, and the navigation bar is still visible. But when I start typing in the search bar, the navigation bar disappears, replaced by a blank area. I tried to add self.searchController.hidesNavigationBarDuringPresentation = NO; in the updateSearchResultsForSearchController: method, but got no result. (note that the controller viewDidLoad defines self.definesPresentationContext = YES;)
Any idea to force navigation being displayed anytime?
I was seeing the same effect - in my case setting the property in viewDidLoad in my view controller made the navigation bar stick around:
- (void)viewDidLoad {
...
self.definesPresentationContext = YES;
...
}
When I'd previously set the same property from a class that was managing the search (initialized after -viewDidLoad had already been called on the VC), I saw the same behaviour of a blank nav bar that you describe.
This work for me
self.navigationController.navigationBar.translucent = true;
I tried several solutions from SO for this problem but none of them worked for me. I created a new iOS7 project with one simple view. I tried setting
View controller-based status bar appearance to NO
and in AppDelegate:
[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
However this removes the status bar completely.
Without the View controller-based status bar appearance option, Regardless what I set for Status bar style in the plist file, the status bar text is still black. I need it to be white for the entire application. Is this possible?
I am on latest xcode version.
did you try it without "Animated:No" ?
Go to Info tab of the project target, Add Row:
UIViewControllerBasedStatusBarAppearance, set value NO
Then in appdelegate.m
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[application setStatusBarStyle:UIStatusBarStyleLightContent];
}
This should set it application wide.
The Accepted answer seemed to work sometimes. I found out that the UIViewController can change the status bar style also. To get around this and always work, cause I didn't need the UIViewControllers controlling the status bar, I had to set UIViewControllerBasedStatusBarAppearance to NO in my Info.plist
Use needsStatusBarAppearanceUpdate to update status bar in viewDidLoad: method of view controller
[self setNeedsStatusBarAppearanceUpdate];
Now add below method into view controller:
- (UIStatusBarStyle) preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
I would go with Logan's answer. As of iOS 9, UIApplication's setStatusBarStyle: method is deprecated anyway, so you'll want to start moving away from using that. The preferred method, now is to implement preferredStatusBarStyle within your ViewController like Logan has described.
I am making an app that requires the status bar to be hidden on one screen, but I then want it to come back on when the user goes back to the previous screen. I am using [[UIApplication sharedApplication] setStatusBarHidden:NO];, which works, but when I turn it on, it overlaps the navigation bar and slows the app down to the point that it crashes. Is there anything else I can use, or am I just not using the code correctly?
I had what would seem to be a similar problem in moving from a DetailView to a FlipView - in which I wanted to have the status bar hidden to show a photo against a black background - and then back to the DetailView. The key thing seemed to be to have the code to revert the hiding in the viewWillDisappearAnimated method of the FlipView, rather than in its ViewDidUnload method or in a method in the DetailView controller. I suppose this resets everything before you return to your previous view. So my code in my FlipViewController was:
- (void)viewDidLoad
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
// other application-specific code
}
and
- (void)viewWillDisappear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}
Hope this helps.
I've followed a how-to to create a simple Tab bar controller with a navigation controller in the first tab. Until here all is working correctly, expect a strange issue on the layout.
When the app starts the first time, the Navigation Bar on the top of the first loaded nib is a little outside of the view. I cannot figure out why this happen. In the first view there is a button "Add new System" that opens a modal view. If I press this button and the modal view appears and then I dismiss the modal going back to the initial view, then the Navigation bar at the top is placed/refreshed correctly. The same happens if I press the second TAB (it's a simple nib without Navigation controller for now) and then back to the first TAB, the Navigation bar is placed in the correct position.
Here a screenshot on the first startup:
And here when I press the modal view or the second TAB and then back to the first view:
The code is quit simple following one of the numerous tutorials on the net. I'm NOT using storyboard. Only customization was adding the buttons on the top of the Navigation Bar:
UIImage *editbuttonImage = [UIImage imageNamed:#"edit_pressed.png"];
UIButton *editButton = [UIButton buttonWithType:UIButtonTypeCustom];
[editButton setBackgroundImage:editbuttonImage forState:UIControlStateNormal];
editButton.frame = CGRectMake(0, 0, editbuttonImage.size.width, editbuttonImage.size.height);
[editButton addTarget:self action:#selector(leaveEditMode)
forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithCustomView:editButton];
[editButton release];
[editbuttonImage release];
No other modifications were made. The nib was used before in a single view. Then I've tried to insert it into a TAB Controller + Navigation Controller.
I could post the whole code in case it's needed. Under Select System there is a Table View, in these pictures empty, also not shown.
Thank's for the help!
Simon
I've solved the issue myself. On startup I've setup to hide the status bar and shown it again in the app delegate. The directive used :
[[UIApplication sharedApplication] setStatusBarHidden:NO];
was after adding the navController as subview. Also the Navigation controller BAR was not out of the view, simply under the status bar.
Hope this helps someone :)
Cheers, Simon
I am really new to iPhone development and I need help setting up my views.
I have a view that is named FirstViewController.xib and a controller class for this view.
In my MainWindox.xib I have setup a root controller with a moveToNextView function that is connected to the options bar button item.
So when I click on this item the current view switches to the first view and I am able to swticht back. That works fine so far.
The navigation bar at the top of the screen from the MainWindow.xib is displayed in the first view, too. But when I open FirstViewController.xib there isn't any navigation bar defined (but on build&run it is displayed).
This is a problem for me because I want to add a save bar item to the first view. How do I solve that?
Assuming you have a UIViewController (or UIViewController subclass) that is a child of a UINavigationController. Note, I'm using storyboards so your results may vary when using xibs.
If you do not see a UINavigationBar on the interface, try manually changing the simulated metrics.
Drag a Navigation Item onto the view (anywhere). You should now have a place to enter the title in the interface builder.
Now you can drag Bar Button Items onto the nav bar.
You have to do it from code. Add to your FirstViewController class viewDidLoad method:
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:#"Save" style:UIBarButtonItemStyleDone target:self action:#selector(doSave:)];
self.navigationItem.rightBarButtonItem = anotherButton;
[anotherButton release];
Just drag a bar button item onto your nav bar in Interface Builder. Xcode automatically wires it up then you can use it like anything else...