简体   繁体   English

如何在Swift中更改TabBar的颜色? 在导航栏中作为背景图像?

[英]How to change the color of a TabBar in Swift? Image as Background in Navigation bar?

I'm trying to change the color of my TabBar from the default color to a different color? 我正在尝试将TabBar的颜色从默认颜色更改为其他颜色吗? How do I do this programmatically with swift? 如何以编程方式快速完成此任务? Also, how do I assign an image as the background for a navigation bar? 另外,如何将图像指定为导航栏的背景? Sorry if this is an easy question, I'm new to programming. 抱歉,如果这是一个简单的问题,我是编程新手。

let's say if you have a tab bar controller. 假设您有一个标签栏控制器。 you can do something like this in viewDidLoad() 你可以在viewDidLoad()中做类似的事情

self.tabBarController?.tabBar.backgroundColor = UIColor.redColor()
self.tabBarController?.tabBar.tintColor = UIColor.blueColor()

and for navigation controller image 和导航控制器图像

  var image = UIImage(named: "filename")
  self.navigationController?.navigationBar.setBackgroundImage(image, forBarMetrics: UIBarMetrics.Default)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 以编程方式更改标签栏和导航栏的颜色 - Change the color of tabbar and navigation bar programmatically 如何仅在快速代码中更改TabBar标题字符串的背景颜色 - How to change the background color of TabBar title string only in swift code 如何更改 Swift 5 中导航栏标题的颜色? - How to change the color of the title of a Navigation Bar in Swift 5? Swift如何为一个视图而不是所有视图更改状态栏的背景颜色 - Swift how to change the background color of status bar lise navigation bar for a view, not all view 如何在SWIFT IOS中更改导航栏背景? - How to change the navigation bar background in SWIFT IOS? 如何更改导航栏的背景颜色和导航文本颜色 - how to change background color of the navigation bar and navigation text color swift:更改导航栏的颜色 - swift: change the color of the navigation bar 如何用动画更改导航栏的背景图像? - How to change the background image of navigation bar with animation? 如何更改状态栏的背景颜色而不更改导航栏的背景颜色? - How to change background color of status bar but not that of navigation bar? 如何在 swift 3 中更改 TabBar 中禁用的项目颜色? - how to change disabled item color in TabBar in swift 3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM