Reputation: 8957
I had an application in which I am adding the images for the UITabBarItems
programatically like this..
UIImage *selectedImage0 = [UIImage imageNamed:@"home_hvr.png"];
UIImage *unselectedImage0 = [UIImage imageNamed:@"home.png"];
UIImage *selectedImage1 = [UIImage imageNamed:@"star_hvr.png"];
UIImage *unselectedImage1 = [UIImage imageNamed:@"star.png"];
UITabBar *tabBar = self.tabbarcontroller.tabBar;
self.tabbarcontroller.tabBar.barStyle = UIBarStyleBlack;
self.tabbarcontroller.tabBar.translucent = NO;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
[item0 setSelectedImage:[selectedImage0 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item0 setImage:[unselectedImage0 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item1 setSelectedImage:[selectedImage1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item1 setImage:[unselectedImage1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
since the tabbaritems doesn't have any titles it will bring a blank space at the bottom of the tab-bar pulling the image above the tab bar,I need no titles but needs to put my image inside the tab bar completely. Can any body guide me on this?
Upvotes: 0
Views: 176
Reputation: 8957
UITabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
was done this trick worked for me .thanks
Upvotes: 1
Reputation: 2225
Try below code:
[[self.tabBarController.tabBar.items objectAtIndex:0] setFinishedSelectedImage:[UIImage imageNamed:@"offer_btn_active.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"offer_btn.png"]];
[[self.tabBarController.tabBar.items objectAtIndex:1] setFinishedSelectedImage:[UIImage imageNamed:@"merchant_btn_active.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"merchant_btn.png"]];
Upvotes: 0