How to add images on tab bar programmatically in iOS (Xcode 4.2)?
I already asked question but did not get a satisfied answer at Could not set tab bar image in Xcode 4.2 Programmatically.
How to add images on tab bar programmatically in iOS (Xcode 4.2)?
I already asked question but did not get a satisfied answer at Could not set tab bar image in Xcode 4.2 Programmatically.
Try the following code
UITabBarItem *tabItem = [[[UITabBarItem tabBar] items] objectAtIndex:yourIndex];
[tabItem setTitle:@"theTitle"];
[tabItem setImage:[UIImage imageNamed:@"yourImage.png"]];
iOS 5 Appearance api,
UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
also see this thread, second highest voted answer explains both cases <5.0 and =>5.0 case.
Write this method in your ViewController:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.tabBarItem.image = [UIImage imageNamed:@"image.png"];
}
return self;
}