【问题标题】:NavigationBar backgroundColor not coloring statusbar backgroundNavigationBar backgroundColor 不着色状态栏背景
【发布时间】:2020-07-24 08:33:02
【问题描述】:

我在为导航栏着色时遇到了一些问题。我尝试使用一些不同教程中的不同方法,但似乎没有什么能按照我想要的方式工作。 我在我的 AppDelegate 中使用以下代码:

    let navAppeareance = UINavigationBarAppearance()

    navAppeareance.configureWithOpaqueBackground()
    navAppeareance.backgroundColor = .systemRed

    //Setup buttons
    let buttonDone = UIBarButtonItemAppearance(style: .done)
    buttonDone.normal.titleTextAttributes = [.foregroundColor: UIColor.white]
    navAppeareance.doneButtonAppearance = buttonDone

    let buttonPlain = UIBarButtonItemAppearance(style: .plain)
    buttonPlain.normal.titleTextAttributes = [.foregroundColor: UIColor.white]
    navAppeareance.buttonAppearance = buttonPlain

    //Set appearances
    UINavigationBar.appearance().standardAppearance = navAppeareance
    UINavigationBar.appearance().scrollEdgeAppearance = navAppeareance

    UINavigationBar.appearance().backgroundColor = .systemRed

以上代码产生以下结果: 我希望状态栏与导航栏颜色相同,但它采用视图背景颜色的颜色。

【问题讨论】:

  • 我已经在我新创建的示例应用程序中检查了您的代码,它运行良好
  • @MidhunMP 我的代码的问题是该栏在使用时会以某种方式变得透明。因此,当我使用上面的代码在 tableview 上滚动时,文本和颜色会与 tableview 重叠。

标签: ios swift xcode uinavigationbar uicolor


【解决方案1】:

在 AppDelegate 中使用它

let navBarAppearnce = UINavigationBar.appearance()
navBarAppearnce.barTintColor = UIColor.red // the color you want

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-26
    • 2015-06-01
    • 2019-11-20
    • 2018-04-10
    • 2016-10-16
    相关资源
    最近更新 更多