0

I am trying to change the status bar color to match the color of a header in my app. The problem is, the app is just a WKWebView loading a web app inside it, so I need to set the status bar to match a header of a website.

I have been trying to figure this out, and have tried several things:

  • Setting the tint/background color of the main view
  • Setting the tint/background color of the WKWebView
  • Setting the UINavigationBarStyle

I haven't been able to get it to work at all.

For reference, here is a picture of the main bar (inside the WKWebView, and the status bar. I need a way to make them the same color.

Main header and status bar

EDIT: I found a solution here, but it only works on the iPhone 8 and below. This solution doesn't work on the iPhone X or above because there is no way to modify it so that it always fits the height of the status bar. Not that I can find at least.

MattChris
  • 397
  • 4
  • 19

1 Answers1

1

Make following change in AppDelegate.siwft didFinishLaunchingWithOptions method

    UINavigationBar.appearance().barTintColor = .init(red: 65.0/255, green: 151.0/255, blue: 176.0/255, alpha: 1.0)
    UINavigationBar.appearance().tintColor = .white
    UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor.white]
    UINavigationBar.appearance().isTranslucent = false
Vikash Kumar
  • 642
  • 1
  • 11
  • 25
  • When I added the code, it threw the error: `Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value` on the line that deals with setting the font. Is it maybe the name of the font that was used? – MattChris Sep 28 '18 at 02:40
  • @Koala King I have updated the code to use it .if any issue let me know. – Vikash Kumar Sep 28 '18 at 05:49
  • 1
    There was no change when I applied the code. I don't get the error, but the status bar still didn't change? – MattChris Sep 28 '18 at 21:46