由于setStatusBarStyle
在iOS 10中被弃用,有没有办法在滚动浏览视图之类的事情时将我的状态栏从白色更改为黑色,反之亦然?
我在UIViewController
上看到了 preferredStatusBarStyle
属性,但我想要更精细的东西,以便在用户使用视图控制器本身时进行控制。
如果你覆盖了preferredStatusBarStyle,然后在需要时调用setNeedsStatusBarAppearanceUpdate((,那应该以同样的方式工作。
class MyViewController: UIViewController {
var currentStyle = UIStatusBarStyle.default
override var preferredStatusBarStyle: UIStatusBarStyle {
return currentStyle
}
// ...
// here are the actions that change the status bar
func myFunction(){
// ...
// condition that would determine the preferred style
currentStyle = .lightContent
setNeedsStatusBarAppearanceUpdate()
}
}