应用运行时如何更改NavigationBarColor

用户名

我使用它来设置NavigationBarColor在运行之前:

 UINavigationBar.appearance().barTintColor = Color.NavigationBackground

但是在程序中,我想更改NavigationBarColor,所以我再次使用它

 UINavigationBar.appearance().barTintColor = Color.Black

但是什么也没发生,仍然是白色(Color.Background)。Color
是我定义的结构。
如何正确改变颜色?我想这样实现:尝试重新加载视图控制器以更新当前主题

尼克·古德

如果您希望每个屏幕具有不同的颜色,则将在您选择的颜色下面添加一行,以供您查看。它将改变每个屏幕的颜色。

Swift 4.2:

//To change Navigation Bar Background Color
UINavigationBar.appearance().barTintColor = UIColor.blue
//To change Back button title & icon color
UINavigationBar.appearance().tintColor = UIColor.white
//To change Navigation Bar Title Color
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]

在视图中添加它会出现,然后您可以看到它在变化。

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.navigationController?.navigationBar.barTintColor = .orange
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章