在Swift中更改导航栏颜色 [英] Changing navigation bar color in Swift

查看:464
本文介绍了在Swift中更改导航栏颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Picker View来允许用户为整个应用选择颜色主题。我打算改变导航栏,背景和标签栏的颜色(如果可能的话)。我一直在研究如何做到这一点,但找不到任何Swift示例。任何人都可以给我一个代码示例,我需要用来更改导航栏颜色和导航栏文本颜色? (Picker View已设置,我只是在寻找更改UI颜色的代码)

I am using a Picker View to allow the user to choose the colour theme for the entire app. I am planning on changing the colour of the navigation bar, background and possibly the tab bar (if that is possible). I've been researching how to do this but can't find any Swift examples. Could anyone please give me an example of the code I would need to use to change the navigation bar colour and navigation bar text colour? (The Picker View is set up, I'm just looking for the code to change the UI colours)

谢谢。

推荐答案

导航栏:

navigationController?.navigationBar.barTintColor = UIColor.green

将greenColor替换为您想要的任何UIColor,如果您愿意,也可以使用RGB。

Replace greenColor with whatever UIColor you want, you can use an RGB too if you prefer.

导航栏文字:

navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.orange]

将orangeColor替换为您喜欢的任何颜色。

Replace orangeColor with whatever color you like.

标签栏:

tabBarController?.tabBar.barTintColor = UIColor.brown

标签栏文字:

tabBarController?.tabBar.tintColor = UIColor.yellow

在最后两个,替换brownColor和yellowColor与您选择的颜色。

On the last two, replace brownColor and yellowColor with the color of your choice.

这篇关于在Swift中更改导航栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆