I use the following code to create image for my UITabBarItem
self.tabBarItem.image = [UIImage imageNamed:@"tab_img.png"];
This tab_img.png consists of black, white and clear color. But in app all part of image that is black and white turns to grey. How I can change this grey to white ?
backgroundColor = UIColor(red:1, green:0, blue:0, alpha:1) / UITabBar. appearance(). tintColor = UIColor(red: 1, green: 0, blue: 0, alpha: 1) // New!! func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {...}
In iOS7, if you use IB you can subclass UITabBarController then add this:
+ (void)initialize
{
//the color for the text for unselected tabs
[UITabBarItem.appearance setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor redColor]} forState:UIControlStateNormal];
//the color for selected icon
[[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
}
- (void)viewDidLoad
{
[super viewDidLoad];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
for (UITabBarItem *tbi in self.tabBar.items) {
tbi.image = [tbi.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
}
}
if you create the items manualy you must set the UIImageRenderingModeAlwaysOriginal on each icon and add the code from initialize.
If you are using image assets, just set the field "Render As" of your images (selected and unselected images) to "Original Image" (example)
Then in your xib set "Image" and "Selected Image" fields on your Tab Bar Item (example)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With