Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 1338 Vote(s) - 3.55 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Changing the Status Bar Color for specific ViewControllers using Swift in iOS8

#31

I had set specific color (in RGB format) using below code in `App Delegate` file:



func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
. . .

UIApplication.sharedApplication().statusBarHidden = false
UIApplication.sharedApplication().statusBarStyle = .LightContent

let statusBar: UIView = UIApplication.sharedApplication().valueForKey("statusBar") as! UIView
if statusBar.respondsToSelector(Selector("setBackgroundColor:")) {
statusBar.backgroundColor = UIColor.init(red: 0.1, green: 0.27, blue: 0.60, alpha: 1.0)
}

. . .
}

You also need to add below key in `Info.plist` file :

**View controller-based status bar appearance** with boolean value set to **NO**

[![Screenshot 1][1]][1]


[![Screenshot 2][2]][2]


[1]:

[2]:
Reply

#32
**SWIFT 2**

I was able to successfully change the appearance of the status bar background by adding the following in my viewWillAppear:

let statusBar: UIView = UIApplication.sharedApplication().valueForKey("statusBar") as! UIView

if statusBar.respondsToSelector(Selector("setBackgroundColor:")) {
statusBar.backgroundColor = .redColor()
}
Reply

#33
override func viewWillAppear(animated: Bool) {
self.navigationController?.navigationBarHidden = true

UIApplication.sharedApplication().statusBarHidden = false
UIApplication.sharedApplication().statusBarStyle = .LightContent

let statusBar: UIView = UIApplication.sharedApplication().valueForKey("statusBar") as! UIView
if statusBar.respondsToSelector("setBackgroundColor:") {
statusBar.backgroundColor = UIColor.redColor()
}

}
Reply

#34
Works for Navigation Based Application

var addStatusBar = UIView()
addStatusBar.frame = CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 20);
addStatusBar.backgroundColor = global().UIColorFromRGB(0x65b4d9)
self.window?.rootViewController?.view .addSubview(addStatusBar)
Reply

#35
In my situation,I use storyboard to organize my view controllers.I want to change all status bar style.

You can see in picture below.

[![enter image description here][1]][1]


`Stars` View Controller is a `CPBaseNavigationController`,and `CPBaseNavigationController` is subclass of `UINavigationController`.

I try doing the next setps:

1. In `AppDelegate.swift` func `didFinishLaunchingWithOptions`,add

//change status bar color
UIApplication.sharedApplication().statusBarHidden = false
UIApplication.sharedApplication().statusBarStyle = .LightContent
but no effect.

2. In StoryBoard,find the `Base Tab BarController`(picture on the above).select `Attributes Inspector`, change the `Sattus Bar` attribute to `Light Content`.so bad,no effect.

[![enter image description here][2]][2]

3. Last I get it.In my custom navigation controller `CPBaseNavigationController`,add func `preferredStatusBarStyle`

override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}
It works well!

**Besides,`statusBarStyle` deprecated in 9.0,you can use `-[UIViewController preferredStatusBarStyle]`.**

[1]:

[2]:
Reply

#36
In your Info.plist you need to define View controller-based status bar appearance to any value.

If you define it YES then you should override preferredStatusBarStyle function in each view controller.

If you define it NO then you can set style in AppDelegate using

UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)
Reply

#37
Click on the Supporting Files group(left side top - name of your project). Navigate to Info. Click on + somewhere between lists, like below bundle name. And add "View controller-based status bar appearence" and set it to NO.
Then open AppDelegate.swift and modify like this:

func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {

UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)

return true
}

Thats it.
Reply

#38
Implement `preferredStatusBarStyle` as you mentioned and call `self.setNeedsStatusBarAppearanceUpdate()` in `ViewDidLoad` and
also in Info.plist set `UIViewControllerBasedStatusBarAppearance` to `YES` (It's `YES` by default)

It is not clear why it is not working.I need to check code.One other suggestion is
go with working code in `viewDidLoad` `UIApplication.sharedApplication().statusBarStyle = .LightContent` and change this to default when you view get disappeared `viewWillDisappear`.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through