Changing the background color of Tab Bar

IosSwiftUitabbarcontrollerUitabbar

Ios Problem Overview


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 :-

  1. Changing the background color of tab bar object from storyboard. The color rendered is always lighter than the desired color.

  2. 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?

Ios Solutions


Solution 1 - Ios

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

Solution 2 - Ios

We can also do it from Storyboard

  1. Select the Tab Bar first:

enter image description here

  1. Then from the Attribute Inspector choose Bar Tint colour as shown in the below image:

enter image description here

That's it!

Solution 3 - Ios

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.

Solution 4 - Ios

try this code

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

Solution 5 - Ios

swift 5

self.tabBarController.tabBar.backgroundColor = .white

Solution 6 - Ios

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMrDankView Question on Stackoverflow
Solution 1 - IosAbhinandan PratapView Answer on Stackoverflow
Solution 2 - IosAnurag SharmaView Answer on Stackoverflow
Solution 3 - IosTrevorView Answer on Stackoverflow
Solution 4 - IosMadhumithaView Answer on Stackoverflow
Solution 5 - Ioszeyad taherView Answer on Stackoverflow
Solution 6 - IosNarenView Answer on Stackoverflow