我使用一个拾取器视图,以允许用户选择整个应用程序的颜色主题。
我计划改变导航栏,背景和标签栏的颜色(如果可能的话)。
我一直在研究如何做到这一点,但找不到任何Swift示例。谁能给我一个例子,我需要用来改变导航栏颜色和导航栏文本颜色的代码?
Picker视图已设置,我只是寻找代码来改变用户界面的颜色。
发布于 2014-07-11 06:48:41
导航栏:
navigationController?.navigationBar.barTintColor = UIColor.green
将greenColor替换为您想要的任何UIColor,如果您愿意,也可以使用RGB。
导航栏文本:
navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.orange]
用你喜欢的任何颜色替换orangeColor。
选项卡栏:
tabBarController?.tabBar.barTintColor = UIColor.brown
选项卡栏文本:
tabBarController?.tabBar.tintColor = UIColor.yellow
在最后两个颜色中,将brownColor和yellowColor替换为您选择的颜色。
发布于 2014-07-11 06:56:59
下面是一些非常基本的外观定制,您可以在整个应用程序中应用它们:
UINavigationBar.appearance().backgroundColor = UIColor.greenColor()
UIBarButtonItem.appearance().tintColor = UIColor.magentaColor()
//Since iOS 7.0 UITextAttributeTextColor was replaced by NSForegroundColorAttributeName
UINavigationBar.appearance().titleTextAttributes = [UITextAttributeTextColor: UIColor.blueColor()]
UITabBar.appearance().backgroundColor = UIColor.yellowColor();
Swift 5.4.2:
UINavigationBar.appearance().backgroundColor = .green // backgorund color with gradient
// or
UINavigationBar.appearance().barTintColor = .green // solid color
UIBarButtonItem.appearance().tintColor = .magenta
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.blue]
UITabBar.appearance().barTintColor = .yellow
有关Swift中UIAppearance
应用编程接口的更多信息,请阅读here。
发布于 2015-08-10 15:24:19
UINavigationBar.appearance().barTintColor = UIColor(red: 46.0/255.0, green: 14.0/255.0, blue: 74.0/255.0, alpha: 1.0)
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]
只需将此行粘贴到代码的didFinishLaunchingWithOptions
中即可。
https://stackoverflow.com/questions/24687238
复制相似问题