Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

  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?

like image 959
MrDank Avatar asked Apr 26 '16 10:04

MrDank


People also ask

How do I change the color of a tab in access?

Set the tab control to transparent. Behind the tab, place a non-transparent box. Then in the OnChange event of the tab, change the background color of the box behind the tab.


2 Answers

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 
like image 164
Abhinandan Pratap Avatar answered Oct 17 '22 04:10

Abhinandan Pratap


We can also do it from Storyboard

1) Select the Tab Bar first:

enter image description here

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

enter image description here

That's it!

like image 20
Anurag Sharma Avatar answered Oct 17 '22 03:10

Anurag Sharma