0

Before I start I would to apologise if this question is duplicated as I seen plenty of question but I can't find out what I need.

I want to create a global Status, navigation, toolbar bar style and, if possible, the bottom part of the view on iPhones X onwards from my app delegate only so I don't have to set it form each Viewcontroller.

So far I have:

extension UIApplication {

    var statusBarView: UIView? {
        return value(forKey: "statusBar") as? UIView
    }

}

and a function called inside the didFinishLaunchingWithOptions method

private func setupNavigationBarStyle(){

     UIApplication.shared.statusBarView!.backgroundColor = UIColor.AppColors.statusBar
     UIApplication.shared.statusBarStyle = .lightContent
     UINavigationBar.appearance().barTintColor = .brown
     UINavigationBar.appearance().tintColor = .green
     UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.yellow]
     UINavigationBar.appearance().isTranslucent = false

    }

I attach a dummy design for my view controller using the storyboard enter image description here

and the final result is enter image description here

Despite not being the best design I have 3 questions.

  • UIApplication.shared.statusBarStyle = .lightContent is deprecated and it shows a warning and I don't want that.

  • How can I change the color for the bottom for iPhone X onwards (currently in red and and where the Horizontal line is).

  • Can I change statusBarStyle for another not defined and change the text color in my status bar Purple?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Reimond Hill
  • 4,278
  • 40
  • 52
  • 1
    I removed the [xcode] tag as your question is not about xcode. You are just using it – Scriptable Oct 25 '18 at 10:30
  • https://stackoverflow.com/questions/38740648/how-to-set-status-bar-style-in-swift-3 for the first one. But the bottom bar question should be on another topic. – Larme Oct 25 '18 at 10:30
  • I saw this question but it doesn't work as I want. The main reason is preferredStatusBarStyle is not called when my UIViewController is not embedded in a UINavigationController – Reimond Hill Oct 25 '18 at 10:37

1 Answers1

1

I hope it will help you

  • UIApplication.shared.statusBarStyle = .lightContent is deprecated and it shows a warning and I don't want that.

    Go to Project -> Target, Set Status Bar Style to Light

    • How can I change the color for the bottom for iPhone X onwards (currently in red and and where the Horizontal line is).

    it is not possible to modify the color, and you shouldn’t worry about it, since it’s out of your control and guaranteed to be visible.For Info(https://medium.freecodecamp.org/reverse-engineering-the-iphone-x-home-indicator-color-a4c112f84d34).

    • Can I change statusBarStyle for another not defined and change the text color in my status bar Purple?

      func setStatusBarBackgroundColor(color: UIColor) {
      
          guard let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView else { return }
              statusBar.backgroundColor = color
      }
      
      //Use self.setStatusBarBackgroundColor(color: .purple)
      

Thanks

V D Purohit
  • 1,179
  • 1
  • 10
  • 23