user2783443
user2783443

Reputation: 91

Custom color and alpha in tab bar

i'm trying to change the color of a tabbar in my app, i use this line of code to change the color of it:

[[UITabBar appearance] setBarTintColor:[UIColor greenColor]];

I want to add a translucent iOS 7 effect but with a green color. I've changed translucent property but i don't see any result.

Upvotes: 0

Views: 1182

Answers (2)

enlyte
enlyte

Reputation: 2827

You can either set the color on the storyboard by selecting the root: Tab Bar View Controller, select the tab bar, and adjust the Background (or tint) color in the attributes inspector, or you can adjust the code with the barTintColor:

// Adjust the Color of the Tab Bar itself
self.tabBar.barTintColor = [UIColor redColor];

// Adjust the Color of the selected Icon in the Tab Bar
self.tabBar.tintColor = [Single single].singleThemeColorTint;

If you need to adjust the ALPHA too, I would use:

UIColor *charcoal = [UIColor colorWithRed:66/255.0
                                            green:79/255.0
                                             blue:91/255.0
                                            alpha:1];
  	// For Tab Bar
    self.tabBar.barTintColor = charcoal;

	// For selected Item Highlight
    self.tabBar.tintColor = charcoal;

I created a View Controller File for the Tab Bar Story Board, and ran this code in ViewDidLoad{ }

Upvotes: 0

Gabriel.Massana
Gabriel.Massana

Reputation: 8225

Change UITabBarController's alpha:

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UITabBarController *tabBarController = (UITabBarController *) self.window.rootViewController;

    [tabBarController.tabBar setBarTintColor:[UIColor greenColor]];
    [tabBarController.tabBar setAlpha:0.2];

}

or with appearance in the same application: didFinishLaunchingWithOptions:

[[UITabBar appearance] setBarTintColor:[UIColor greenColor]];
[[UITabBar appearance] setAlpha:0.2];

Upvotes: 1

Related Questions