-2

I wanted to know how to achieve a darker statusbar color than the navbar color like youtube did in it's new app (material design) using Swift.

EDIT

I want the design of the new app design. Not the old one. And this is not related to just changing the status bar text color. So which ever knob implied its a duplicate has no comprehension skills

Like this

Palash Sharma
  • 662
  • 1
  • 10
  • 18
  • Possible duplicate of [how do I properly change my status bar style in swift 2/ iOS 9?](http://stackoverflow.com/questions/32674315/how-do-i-properly-change-my-status-bar-style-in-swift-2-ios-9) – MQLN Nov 14 '15 at 04:52
  • You might want to read this answer through: http://stackoverflow.com/a/19585104/433373 – Nicolas Miari Nov 14 '15 at 05:01
  • Sorry, I meant this one better: http://stackoverflow.com/a/18855464/433373 – Nicolas Miari Nov 14 '15 at 05:09

2 Answers2

0

So I figured out that I have to add a subview over the navbar and then add a darker shade of red as background of the view. This can either be used in a UINavigationClass if your navbar color is the same throughout the app or it can be added in a viewcontroller to make it different.

Palash Sharma
  • 662
  • 1
  • 10
  • 18
0

You can change the background of the status bar like youtube in this way:

AppDelegate

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

        // Step 1
        window = UIWindow(frame: UIScreen.mainScreen().bounds)
        window?.makeKeyAndVisible()


        //Step 2
        UINavigationBar.appearance().barTintColor = UIColor.rgb(230, green: 32, blue: 32)
        application.statusBarStyle = .LightContent

        // Step 3
        let statusBarBackgroundView = UIView()
        statusBarBackgroundView.backgroundColor = UIColor.rgb(194, green: 31, blue: 31)

        window?.addSubview(statusBarBackgroundView)
        window?.addConstraintsWithFormat("H:|[v0]|", views: statusBarBackgroundView)
        window?.addConstraintsWithFormat("V:|[v0(20)]", views: statusBarBackgroundView)


        return true
    }


extension UIColor {
    static func rgb(red: CGFloat, green: CGFloat, blue: CGFloat) -> UIColor {
        return UIColor(red: red/255, green: green/255, blue: blue/255, alpha: 1)
    }
}


extension UIView {
    func addConstraintsWithFormat(format: String, views: UIView...) {
        var viewsDictionary = [String: UIView]()

        for(index, view) in views.enumerate() {
            let key = "v\(index)"

            view.translatesAutoresizingMaskIntoConstraints = false
            viewsDictionary[key] = view
        }

        addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(format, options: NSLayoutFormatOptions(), metrics: nil, views: viewsDictionary))
    }
}

Result

enter image description here

Jorge Casariego
  • 21,948
  • 6
  • 90
  • 97