Change status bar text colour when using swiftui? - ios

Looking to change the status bar text colour (on a per view basis) using swiftui but cannot seem to do it?
I can change it for the whole app but some screens have a different status bar colour so the text needs to switch from black to white when the background is dark?
Any ideas on how to achieve this?

Related

How to change StatusBar in swiftUI?

Where is the correct place to write the code for Status Bar, and How can to change the Status Bar light or dark in SwiftUI?

Is there a way to set custom color for status bar text and background?

I know how to change text color to black or white, but is there some way to change text to green and BG to red for example?
The text of the status bar may only be black or white. You can read more in Apple's iOS Human Interface Guidelines.
The background color is based on what is behind the status bar. You could, for example, add a 20-pixel tall view with a solid color at the top of your view to color it. Here is a description of how to do that programmatically in Objective-C. You can use the same idea using Storyboard.

Set Statusbar color to same as Nav Bar

I want the Status Bar of my app to have the exact same color as my Navigation Bar. The way I found to change the color of the Status Bar was just by creating a view in the size of the Status Bar and change the background color.
However even though I use the color picker from the Nav bar to set the color of the view I get 2 totally different colors as seen in the picture below.
I've tried mixing with the color picker, changing opacity etc, however I'm never able to hit the correct color. Any ideas on how I can get the exact same color for the status bar?
The color of the UIStatusBar is automatically set to match the color of the UINavigationBar when you set the value of self.navigationController.navigationBar.barTintColor. Is there a reason you need to set them separately?
You can do the following:
Create an UIImage containing only the color you want with a size of 64x1. You could render that image in code.
Set the image as a background image for the navigationBar. Something like:
navigationController.navigationBar.setBackgroundImage(image, for: .default)

Changing the status bar color gradually

Changing the status bar's text color in iOS7 is simple and there is a lot of information on that topic.
So, to give you some context, today I saw this tweet:
That links to this video.
I was wondering about how to do that animation and the best way I can think of is:
A screenshot of the status bar with black text color that is inserted on top of the real status bar (with white color) and then the real status bar is slowly revealed.
As #Edgar confirmed it it is really what they are doing in the video (if you keep the finger on the screen while the time changes it is possible to see that).
However, this solution isn't good enough because in the meantime the status bar can change and it can become kinda creepy.
Is there a way to do this without a screenshot?
When you start swiping it does a screenshot of the status bar and puts it at the top of the real status bar and then it changes to style UIStatusBarStyleLightContent to UIStatusBarStyleDefault.
You can clearly see this if you play around with it and start the swipe gesture but do not release it, not only after one minute the clock becomes outdated but if you happen to start swiping when the activityIndicator is on, you'll see it stays static.
Unfortunately, as far as I know there's no way to have two status bars, both with the right info. Maybe if you could come up with a way to continually take screenshots of the real one and dynamically invert colors, but that would be expensive, performance wise.
As i know the status bar color depends on the near by view attached to
status bar.
if it is connected to the navigation bar then status bar takes the
color of the navigation bar.
if navigation bar is hidden then the top view that near to the status
bar that color is taken by the status bar.

Change statusbar tint colour

Is there a way to set the status bar tint colour?
I have my navigationbar tint set to brown and when it's on screen it also changes the statusbar to brown, however on views that I hide the navigationbar the statusbar returns to its original colour.
How can I change the statusbar tint colour to persist trough the application?
There is no way in iOS 5. You can just change your bar style.
But if you take a look at new WWDC 2012 Sessions, you may find something interesting)
Session number 216 - Advanced Appearance Customization on iOS
Maybe keep the notification bar there but cover it up? If the notification bar's color influences that of the status bar, then it would lead me to believe that it just has to be in the window (even buried under another view) to change it.
There is no way in iOS 5 or ealier version of ios.
now ios 6 have feature to change status bar tint color or it will set according to navigation bar pattern Image
But u can use Custom Status Bar
What I do in screens that have no navigation bar is to put in a navigation bar at the top but behind the visible interface. The navigation bar is not visible to the user, but it is visible to the system and causes the status bar to adopt its color.
EDIT: Sorry, I see now that someone else had already suggested this. So I'm just confirming that it does work.

Resources