Stephan Boner
Stephan Boner

Reputation: 753

UITabBar Selected Item Tint Color

I'm working on an UITabBar-Application.

I want to change the selected Item Color with

[[UITabBar appearance] setTintColor:[UIColor redColor]]

This works, until I want to set the Background Color of the TabBar with

[[UITabBar appearance] setBarTintColor:[UIColor blueColor]]

Then the Bar is blue, but the highlighted Items are grey.

[[UITabBar appearance] setBackgroundColor:[UIColor blueColor]]

has no effect. Any Idea? Thank you very much!

Upvotes: 1

Views: 1131

Answers (2)

Arnab
Arnab

Reputation: 4356

Your code, that you've posted, seems to be working. You can do it with images too. Try this:

[tabBarItem1 setImage:[[UIImage imageNamed:@"home.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem1 setSelectedImage:[[UIImage imageNamed:@"home_selected.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

// Change the tab bar background
UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_selected.png"]];

Upvotes: 0

Md. Ibrahim Hassan
Md. Ibrahim Hassan

Reputation: 5467

Try this Code

//Set greenColor for normal State
[UITabBarItem.appearance setTitleTextAttributes:@{
        UITextAttributeTextColor : [UIColor greenColor] } forState:UIControlStateNormal];
//Set purpleColor for normal State  


[UITabBarItem.appearance setTitleTextAttributes:@{
        UITextAttributeTextColor : [UIColor purpleColor] }     forState:UIControlStateSelected];

Hope this helps.

Upvotes: 3

Related Questions