简体   繁体   中英

Change color of tab bar

I created an app in iOS 5 using Storyboard to lay out my screens. I have a tab bar controller and the bottom tab bar with 4 icons. I want to change the color from black to a graduated green. I can make a .png file, but can't figure out how to replace the black fill with my green fill.

I've seen some posts on code to do this but seems iOS 5 is different than if the device is running iOS4 and I can't figure out where to put the code.

Thx

Here is what worked for me:

In AppDelegate.m I put the following code after // Override point for customization after application launch.

[[UITabBar appearance] setSelectedImageTintColor:[UIColor redColor]];

Hope this helps :)

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{ }

Here is the wonderful blog post of Ray WenderLich.

User Interface Customization in iOS5

http://www.raywenderlich.com/4344/user-interface-customization-in-ios-5

如果您使用storyboard API创建了应用程序,那么您不能支持iOS4,它们依赖于那里没有的新运行时类。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM