【问题标题】:How can I change the statusBarFrame color to keep the same as the NavigationController in Swift iOS 13 [duplicate]如何更改 statusBarFrame 颜色以与 Swift iOS 13 中的 NavigationController 保持相同 [重复]
【发布时间】:2020-01-29 19:05:57
【问题描述】:

我使用以下代码打开modal。 我正在使用.fullScreen,因为我需要在此controller 被解雇后调用viewWillAppear

let controller = self.storyboard!.instantiateViewController(withIdentifier: "Login")
controller.modalPresentationStyle = .fullScreen
self.present(controller, animated: true, completion: nil)

当控制器出现时:

我的问题是,如何更改顶部颜色以保持与导航相同?

【问题讨论】:

标签: ios swift ios13


【解决方案1】:

对于 iOS 13,您可以使用 UINavigationBarAppearance,如文档和此 answer here 中所示。

if #available(iOS 13.0, *) {
    let navBarAppearance = UINavigationBarAppearance()
    navBarAppearance.configureWithOpaqueBackground()
    navBarAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
    navBarAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
    navBarAppearance.backgroundColor = <insert your color here>
    navigationBar.standardAppearance = navBarAppearance
    navigationBar.scrollEdgeAppearance = navBarAppearance
}

【讨论】:

    猜你喜欢
    • 2020-01-16
    • 2019-10-19
    • 2020-06-16
    • 2020-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多