Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

swift - Set Status Bar Color based on webpage meta color ios

I'm using WKWebView to load a webapp. The webapp has a different meta color value on each page. The meta color is available in a tag of the webpage.

Now, I was wondering if it possible (in any way), to load the HTML meta color value and set it as status bar color?

Thank you in advance.

question from:https://stackoverflow.com/questions/65865211/set-status-bar-color-based-on-webpage-meta-color-ios

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is no way to change the color of the status bar contents like text, icons. You can only switch between dark and light styles of the status bar.

// in your view controller
override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent // or .darkContent or .default
}

You will need to call setNeedsStatusBarAppearanceUpdate() when you want to refresh status bar style.

It is possible to change the background color of the view behind the status bar. Simply make sure that the view is not constrained to the safe area layout guide, but to the topAnchor of the view controller that contains the web view.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...