Reputation: 122
(Hopefully) Quick question!
I would like to make a custom tab bar design. Right now it looks like this:
What I've done is:
But I would like to have the background of the active button be another color, like this:
So:
How can I accomplish this? Thank you.
Upvotes: 0
Views: 894
Reputation: 23634
One way to accomplish this would be following these steps:
Set the background color for the whole tab bar:
tabBar.backgroundColor = [UIColor grayColor];
Have your tab icon images be the color you want them to be (white). Then set up each tab like this:
UIImage *tabImage = [UIImage imageNamed:@"my_image"];
// make sure the original color of the image is used, rather than templating it
tabImage = [tabImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
myViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"title" image:tabImage tag:0];
Set the tintColor
of the tab bar to white also so that the selected tab won't change colors:
tabBar.tintColor = [UIColor whiteColor];
Set the selectionIndicatorImage
to get a blue background on the selected tab. You'll need to create an image either programmatically or by importing it.
Upvotes: 1