ChatGPT解决这个技术问题 Extra ChatGPT

Changing the background color of Tab Bar

I am trying to get desired color rendered in the background of Tab Bar however I am facing problems. These are the things that I tried :-

Changing the background color of tab bar object from storyboard. The color rendered is always lighter than the desired color. Programmatically changing the color of the tab bar using the following code inside viewDidLoad() method self.tabBar.translucent = false self.tabBar.backgroundColor = UIColor(hexString: "323B61") It doesn't change the color. Instead , the color rendered is white.

How can I get the desired color for Tab Bar?


J
Joshua Wolff

To change background colour of UITabBar

TabBarController* Tcontroller =(TabBarController*)self.window.rootViewController;
Tcontroller.tabBar.barTintColor=[UIColor yourcolour];

Swift 3

Based on the code above, you can get it by doing this

let Tcontroller = self.window.rootViewController as? UITabBarController
Tcontroller?.tabBar.barTintColor = UIColor.black // your color

or in more general

UITabBar.appearance().barTintColor = UIColor.black // your color

also do: tabBar.isTranslucent = false
A
Anurag Sharma

We can also do it from Storyboard

1) Select the Tab Bar first:

https://i.stack.imgur.com/y3s4R.png

2) Then from the Attribute Inspector choose Bar Tint colour as shown in the below image:

https://i.stack.imgur.com/ymdeO.png

That's it!


T
Trevor

swift 4

Inside your UITabBarController

tabBar.barTintColor = .purple
tabBar.isTranslucent = false

You also have access to:

tabBar.tintColor = .green
tabBar.unselectedItemTintColor = .blue

to change icon colours if you want.


M
Madhumitha

try this code

self.tabBarController.tabBar.barTintColor =  [UIColor colorWithRed:0.376 green:0.729 blue:0.318 alpha:1.000];

Is barTintColor will work in iOS Devices below version 8.0 ??
g
ganski

swift 5

self.tabBarController.tabBar.backgroundColor = .white

Thank you! So annoying that Apple keeps changing this!
N
Naren

Swift 4, in viewDidLoad of TabBarController

    self.tabBar.tintColor = UIColor.white // tab bar icon tint color
    self.tabBar.isTranslucent = false
    UITabBar.appearance().barTintColor = UIColor.blue // tab bar background color

关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now