【问题标题】:Set border and color of navigationbar when largetitles = true当 largetitles = true 时设置导航栏的边框和颜色
【发布时间】:2021-04-01 13:08:39
【问题描述】:

我将导航栏设置为 preferslargetitles = true。由于某种原因,颜色和底部边框消失了,变成了白色。如果它是标准的,我如何保持它的颜色和边框?

这是大标题的样子:

我想要和下面一样的颜色和边框:

我已经尝试过设置背景颜色,但是边框仍然缺失,状态栏颜色不同。

navigationController?.navigationBar.backgroundColor = UIColor(displayP3Red: 248/255, green: 248/255, blue: 248/255, alpha: 1)

【问题讨论】:

    标签: ios swift xcode uinavigationcontroller


    【解决方案1】:

    我现在开始工作了。如果有人有同样的问题,可以用这个代码来完成:

    if #available(iOS 13.0, *) {
        let appearance = UINavigationBarAppearance()
            appearance.backgroundColor = UIColor(displayP3Red: 248/255, green: 248/255, blue: 248/255, alpha: 1)
            appearance.titleTextAttributes = [.foregroundColor: UIColor.black]
            appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.black]
    
            UINavigationBar.appearance().tintColor = .systemBlue
            UINavigationBar.appearance().standardAppearance = appearance
            UINavigationBar.appearance().compactAppearance = appearance
            UINavigationBar.appearance().scrollEdgeAppearance = appearance
    } else {
        UINavigationBar.appearance().tintColor = .systemBlue
        UINavigationBar.appearance().barTintColor = UIColor(displayP3Red: 248/255, green: 248/255, blue: 248/255, alpha: 1)
        UINavigationBar.appearance().isTranslucent = false
    }
    

    你需要把它放进去

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { }

    否则,第一个视图控制器没有这些更改,因为第一个视图已经加载。

    感谢@Sebastion 在这篇文章中发布了类似的内容:iOS13 Navigation bar large titles not covering status bar

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-01
      相关资源
      最近更新 更多