Okay, so...
I have set the NavigationBar Style to Black so that the Status Bar Icons become White.
(See Pic 1 Below)
The Problem begins with the Search Bar. When it's active and you can type it turns the NavigationBar Style back to Default which makes the Status Bar Icons Black again. Though once you are done with it and it goes back to being inactive, the NavigationBar Style goes back to Black, where it should be all the time.
(See Pic 2 Below)
I haven't found a way yet to make the Status Bar Icons remain White at all times.
Help is much appreciated.
It sounds like you have view controller based status bar appearance setup.
If you want the status bar to be white all the time, then you can set the UIViewControllerBasedStatusBarAppearance info.plist key to NO and then set UIStatusBarStyle key to UIStatusBarStyleLightContent.
If you do want to keep view controller based status bar appearance, then you will need to subclass UISearchController and override the status bar style as you are technically presenting a different view controller for search hence the change in status bar style...
class SearchController: UISearchController {
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}
}
(note that i assume you are using UISearchController as your question doesn't mention your approach)
Related
I have table view controller which is embedded into a navigation controller. Basically I want my app to look like the "alarm" app from iOS: complete app is black including the navigation bar, but I want the top line where the carrier, battery life etc. is shown to be also black but with white text font. How is that possible?
Add this to any/all view controllers:
override var preferredStatusBarStyle : UIStatusBarStyle {
return .lightContent
}
To change the color of the status bar of a specific screen/ViewController, add it to the following class.
override var preferredStatusBarStyle : UIStatusBarStyle {
return .lightContent
}
If you want the whole app to have the same status bar color, then you can do it the following ways -
Inside the project settings - click the project, and under General and Deployment Info select the Status bar style to however you want.
See image for reference
Go to info.plist and add a new row, Type in Status Bar Style and set the value to whichever you want.
I have a ContentPage with a WebView in a NavigationPage with no navigation bar (NavigationPage.SetHasNavigationBar(this, false);).
The problem: the status bar on iOS is always transparent, and content can be seen through it. I want to avoid this, I want an opaque / solid black status bar with white text.
I thought about simply having a coloured rectangle below the status bar with a height of 20 pt, but then how to ensure it has the correct size for iPhone X-type phones, which is 44 pt? (iPhone XS Max, iPhone XR).
NavigationPage.BarBackgroundColor and BarTextColor doesn't seem to make a difference when the navigation bar is hidden.
UIStatusBarStyleBlackOpaque is deprecated.
Setting UIStatusBarStyle with
UIViewControllerBasedStatusBarAppearance == false can change the
colour of the text, but not the background: the background is always
transparent.
I haven't found an answer in other Stack Overflow questions (or anywhere else for that matter).
Creating a coloured rectangle below the status bar is correct.
In a custom page renderer for the page (here called MyPage), create a view/subview (UIView) with a black background that covers up the status bar (i.e. is beneath it, providing a background for it). As far as I understand, since iOS 7, the status bar never has a background and is always translucent.
using MyApp;
using MyApp.iOS;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly:ExportRenderer (typeof(MyPage), typeof(MyPageRenderer))]
namespace MyApp.iOS
{
public class MyPageRenderer : PageRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e.OldElement != null || Element == null)
{
return;
}
UIView statusBarCoverView = new UIView(UIApplication.SharedApplication.StatusBarFrame);
statusBarCoverView.BackgroundColor = UIColor.Black;
View.AddSubview(statusBarCoverView);
}
}
}
Xamarin.Forms NavigationPage will insist on making the status bar text black even with the black background view in place if the previous background was bright, even with BarBackgroundColor and BarTextColor set.
The only way to change this I've found so far is to set UIViewControllerBasedStatusBarAppearance to false in Info.plist, which results in the status bar text to always be white in the entire app:
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
Not ideal, but I haven't found out how to set it otherwise. UIApplication.SharedApplication.StatusBarStyle, PreferredStatusBarStyle or SetNeedsStatusBarAppearanceUpdate() don't seem to work. I suspect this is because the page is a child controller of the NavigationPage controller.
In Xcode I was able to achieve this without using code. First, make sure you are using a Navigation Controller. Then you click on the top Nav bar in that controller and change the Style to "Black", the Bar Tint to Black Color, and the Tint (near the bottom) to White Color. Then it will automatically fill in stuff as expected.
If you just want to make this page not show navigation bar in Xamarin.Forms,
add this page not the root of Navigation Page.
I suggest that when you push to this WebView page ,not use Navigation page, just do that.
Navigation.PushModalAsync(new NextPage());
Not use Navigation.PushAsync(new NextPage());
More info:
If Xamarin.Forms's method can not work , you can try native ios method to do that.
Setting UIStatusBarStyle with UIBarStyleBlack
Setting navigationBar.translucent with NO
translucent :
A Boolean value indicating whether the navigation bar is translucent (YES) or not (NO).
I add Navigation Controller(2nd View) and add one UIViewController(3rd View) as root view controller.
And then I connect segue to Navigation Controller(2nd View) from anther UIViewController(1st View).
So I can see navigation Bar with Status bar space when the view is presented.
But the information like Carriers, batteries, time information are not shown in Status Bar.
(I changed navigation Color to pink for showing you the problem.
The blue part is title view for navigation bar.)
So I tried 2 solutions.
First, I thought StatusBar Color problem. But it was not.
UIApplication.shared.statusBarStyle = .default
Second, I tried following code for showing. It was not also.
override var prefersStatusBarHidden: Bool {
return false
}
and
UIApplication.shared.setStatusBarHidden(false, with: UIStatusBarAnimation.none)
I need to solve this not-showing problem with status Bar.
I can see status Bar space but not information.
There are lots of ways to toggle the color and visibility of the status bar in iOS.
Similar question with possible correct answers for you:
How to change Status Bar text color in iOS 7
In short, if you want to toggle it between every screens, follow these steps:
In your info.plist, add this new key:
View controller-based status bar appearance and value should be NO.
In your viewWillAppear, toggle the status bar with the code you have posted:
UIApplication.shared.statusBarStyle = .lightContent - white
or
UIApplication.shared.statusBarStyle = .default - black
Edit:
Initial ViewController --> Present Modally --> NavigationController + ViewController.
This is how you set up your screens, right?. If so,
You can setup the status bar in your NavigationController properties in your Interface Builder.
And toggle the visibility and/or color of your status bar in side the viewWillAppear of your 3rd ViewController.
I suggest you check out Debug View Hierarchy.
Based on my experiences in previous projects, if I can't come up with code-based solutions on UI-related problems the simplest debugging technique that I can do is check the view hierarchy during run time.
See if the Navigation Controller View blocks the Main View which can possibly hide the status bar and if yes, work your way on solving it.
I hope it helps.
My app uses a white status bar. When I launch the app from the home screen (i.e. the app goes full screen) this works fine.
If, while my app is still in full screen, I Slide Over a second app (Calendar, for instance), the status bar is still white. If I then use Split View between my app and Calendar, the status bar remains white. This is all working properly.
However, if the first full screen app is Calendar (or any other, of course) and I use Slide Over to see my app, the status bar turns to black. If I then proceed and use Split View, the status bar still shows as black. Finally, if I drag my app all the way to the left to make it go full screen, the status bar correctly turns to white.
To sum up: when having another app in full screen and using Slide Over or Split View to see my app, the status bar is displayed using the wrong color.
Is this an iOS 9 bug or am I missing something? I couldn't find anything in the docs that stated to declare the status bar color somewhere else for Slide Over/Split View.
Thanks!
I fixed this issue by creating a new class inheriting from UISplitViewController and assign it as the class for your split view controller. In this class override the method preferredStatusBarStyle as follows
override func preferredStatusBarStyle()-> UIStatusBarStyle {
return UIStatusBarStyle.LightContent
}
Don't actually understand why this works while changing the value in the storyboard doesn't work.
Swift 3 version:
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
I've tried all the solutions I can find including those in: setStatusBarHidden is deprecated in iOS 9.0 but none of them work with my application.
It is a simple, single view application. There is a Navigation bar with a single button on it which the status bar should show on top of.
In my .plist:
Status bar is initially hidden: NO
Status bar style: UIStatusBarStyleLightContent
View Controller based status bar appearance: NO
Changing any of these doesn't seem to make any difference at all. I have the status bar style "Hide during application launch" option checked as I don't want it to appear on the splash screen.
I have:
- (BOOL)prefersStatusBarHidden
{
return NO;
}
-(UIStatusBarStyle)preferredStatusBarStyle
{
NSLog(#"style");
return UIStatusBarStyleLightContent;
}
and setNeedsStatusBarAppearanceUpdate which are definitely all called when the view loads in my ViewController.
The view is established in a .storyboard, but many of the fields are manipulated in the ViewController.m as well. The value assigned to the status bar in the simulated metrics doesn't seem to have any effect either.
I need my status bar to be hidden during the launch screen and visible on the viewController. Please help me find a solution that doesn't use the deprecated setStatusbarHidden!
EDIT:
I still haven't solved this, and I surely can't be the only one with this problem! It happens in both apps that I have written.
I've just been trying to solve the same problem, I don't know why the setStatusBarHidden and setStatusBarStyle have been deprecated as the new methods are not at all intuitive.
To hide the status bar on launch I have these settings in my plist:
View controller-based status bar appearance: YES
Status bar is initially hidden: YES
Then to show the status bar after launch I have in my view controller:
- (BOOL)prefersStatusBarHidden {
return NO;
}
-(UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
This still didn't work until I found this answer https://stackoverflow.com/a/19365160/488611. So in viewDidLoad I also set the navigation bar style:
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
Which makes absolutely no sense, but works.
you can use
application.statusBarHidden=YES;
in AppDelegate.m
didFinishLaunchingWithOptions
In my mind, you should change the value of UIViewControllerBasedStatusBarAppearance.
Set the value file .plist of project a is
UIViewControllerBasedStatusBarAppearance = NO
and check in file AppDelegate and set the code
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
Hope my solution can be solved your problem.
OK, I totally misunderstood your question. Here's the correct answer.
Add the below value to you 'info.plist'.
Status bar is initially hidden : YES
View Controller based status bar appearance : YES
On UIViewControllers which you want to show status bar
- (BOOL)prefersStatusBarHidden {
return NO;
}
That's all.
I am not an expert on this, but I played with these settings for some time and came to the following conclusions.
General/Deployment Info:
Status Bar Style: Default (black), Light
Hide status bar (checkbox)
Both change the status bar on the launch screen only.
Note that if you take a screen shot to create this image and the screen shot included a status bar, it will appear that the device is setting the status bar even if you have checked the Hide status bar checkbox! I was tricked by this for a while before I finally thought to look at the launch image itself, and there was a status bar in the photo, so setting Hide never seemed to work even though it really was working. I removed the status bar from the images themselves using Photoshop, and the launch status bars functioned as expected after that.
Info/Custom iOS Target Properties (these change the values in the PLIST, so you could change them in either place):
Status Bar Is Initially Hidden: Yes/No
Status Bar Style: Gray (default), Transparent Black, Opaque Black
View Controller based status bar appearance : Yes/No
If you set Status Bar Is Initially Hidden to No, then you will have the status bar on your View Controller like you wanted. If you want to hide the status bar on your View Controller, you have to set Status Bar Is Initially Hidden to Yes AND set View Controller based status bar appearance to No.
Attributes Inspector for the View Controller/Simulated Metrics
Status Bar: None, Inferred, Default, Light, Black (deprecated)
This seems to have no effect on anything except the appearance of the view controllers in the StoryBoard but NOT in the simulator.
Summary: To answer your question, under General Deployment Info, check the checkbox that says Hide Status Bar. This will hide the status bar on the launch screen. Make certain that your image for the launch screen does NOT have a picture of a status bar in it. None of the settings in the StoryBoard or in the Target seems to turn off the view controller's status bar, so it seems that it will stay on like you wanted. However, I did not test any of the programmatic settings; I think that you should not do any of those, and it will work the way you want.