0

I have developed tabbar base application which have 5 tabs and i am trying to set images on each tabs. so I've used inbuid functionalities which provide by xcode for setting images but I'm not getting exact results which I want.

here is my TabBar Controller enter image description here

in this case I am getting images in Grey colors but my actual images are not grey its a colored images. so please any one have solution to solve this issues. I want to set image as reties which I have.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • possible duplicate of [How to change inactive icon/text color on tab bar?](http://stackoverflow.com/questions/22767098/how-to-change-inactive-icon-text-color-on-tab-bar) – Srinivasan N Jun 26 '15 at 10:35

2 Answers2

0

Begin from iOS 7, you can choose to treat any of the images in your app as a template—or stencil—image. When you elect to treat an image as a template, the system ignores the image’s color information and creates an image stencil based on the alpha values in the image. UIImage has a new property named renderingMode The default rendering mode is UIImageRenderingModeAutomatic. From my experience it usually means template like image so when you init your image you need

UIImage *image = [UIImage imageNamed:@"someimage"];
UIImage *thisoneshouldbeused = [image imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal]

See Template Images in UIKit User Interface Catalog for more information

dopcn
  • 4,218
  • 3
  • 23
  • 32
0

@Inertiatic has a great answer, use -imageWithRenderingMode:.

NSArray *images = @[@"[FIRST IMAGE]", @"[SECOND IMAGE]", …];
NSArray *selectedImages = @[@"[FIRST SELECTED IMAGE]", @"[SECOND SELECTED IMAGE]", …];

UITabBarController *tabBarController = (id)self.window.rootViewController;

for (NSInteger i = 0; i < tabBarController.tabBar.items.count; ++i) {
    UITabBarItem *item in tabBarController.tabBar.items[i];

    item.image = [[UIImage imageNamed:images[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    item.selectedImage = [[UIImage imageNamed:selectedImages[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
Community
  • 1
  • 1
Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117