【发布时间】:2017-11-28 10:31:59
【问题描述】:
我希望能够更改我的应用程序的状态栏背景颜色,在 3 个特定的 UIViewControllers 上透明,并将其余部分设置为其他颜色。
我不确定如何检查哪个视图控制器是当前视图控制器。它应该是一个 if/else 语句。我的AppDelegate 中有这个:
extension UIApplication {
var statusBarView: UIView? {
return value(forKey: "statusBar") as? UIView
}
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
let appDelegate = UIApplication.shared.delegate as? AppDelegate
if let currentVC = appDelegate?.window?.rootViewController?.getCurrentlyDisplayedVC()
{
if currentVC is LoginVC || currentVC is RegisterVC || currentVC is LostPasswordVC {
UIApplication.shared.statusBarView?.backgroundColor = .clear
} else {
UIApplication.shared.statusBarView?.backgroundColor = Color_Main_Blue
}
}
UIApplication.shared.statusBarStyle = .lightContent
return true
}
【问题讨论】:
-
请检查我的回答。 stackoverflow.com/questions/43073623/…希望对你有帮助!
标签: ios swift uistatusbar