简体   繁体   中英

Set Image on UITabBar Controller

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 在此处输入图片说明

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.

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

@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];
}

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