i want to change the color of my device status bar if the internet is connected than the status bar color should turn Black and if the internet is not connected the color or status bar should turn Red so that it indicates wether internet is working or not during working with the application using SWIFT...help me out
Open your info. plist and set UIViewControllerBasedStatusBarAppearance to false . In the first function in AppDelegate. swift , which contains didFinishLaunchingWithOptions , set the color you want.
Go to the Storyboard. Select the View and in the Attributes Inspector change the Background Color to Light Gray. Build and Run the Project. The default style of the status bar is dark content.
Step 1: After opening the android studio and creating a new project with an empty activity. Step 2: Navigate to res/values/colors. xml, and add a color that you want to change for the status bar. Step 3: In your MainActivity, add this code in your onCreate method.
override func viewWillAppear(animated: Bool) {
self.navigationController?.navigationBarHidden = true
//Status bar style and visibility
UIApplication.sharedApplication().statusBarHidden = false
UIApplication.sharedApplication().statusBarStyle = .LightContent
//Change status bar color
let statusBar: UIView = UIApplication.sharedApplication().valueForKey("statusBar") as! UIView
if statusBar.respondsToSelector("setBackgroundColor:") {
statusBar.backgroundColor = UIColor.redColor()
}
}
In your Info.plist
you need to set "View controller-based status bar appearance" to a boolean value.
If you set it to YES
then you should override preferredStatusBarStyle
function in each view controller.
If you set it to NO
then you can set the style in AppDelegate
using:
UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)
Tested in Swift & iOS9
If you use Navigation Controllers, put this in your viewcontroller class:
override func viewDidLoad(){
...
self.navigationController?.navigationBar.barStyle = .Black
}
Otherwise, override the preferredStatusBarStyle()
in your UIViewController:
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}
You could find more information here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With