if you do not have a large number of view controllers. Here is my way to do it.
In the delegate method, just place your bg Image tab. And install UIImageView
Create a UITabbar intance in AppDelegate.h
@property (nonatomic,retain) UITabBar *tabbar;
AND
@synthesize tabbar; UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController; tabbar = [tabBarController tabBar]; [tabbar setBackgroundImage:[UIImage imageNamed:@"tabbarBg.png"]]; NSArray *tabImageArray = [NSArray arrayWithObjects: [UIImage imageNamed:@"tab1Hover.png"], [UIImage imageNamed:@"tab2.png"], [UIImage imageNamed:@"tab3.png"], [UIImage imageNamed:@"tab4.png"], [UIImage imageNamed:@"tab5.png"], nil]; for (int i = 0; i<5; i++) { UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(20+i*60+i*3.5, 10, 25, 21)]; [image setContentMode:UIViewContentModeScaleAspectFit]; [image setImage:[tabImageArray objectAtIndex:i]]; [image setTag:10+i]; [tabbar addSubview:image]; }
Then each ViewController in the tab adds
-(void)viewWillAppear:(BOOL)animated
delegate the method to this method as well. You can change the images as shown below.
-(void)viewWillAppear:(BOOL)animated{ AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; UITabBarController *tabBarController = (UITabBarController *)appDelegate.window.rootViewController; NSArray *tabImageArray = [NSArray arrayWithObjects: [UIImage imageNamed:@"tab1Hover.png"], [UIImage imageNamed:@"tab2.png"], [UIImage imageNamed:@"tab3.png"], [UIImage imageNamed:@"tab4.png"], [UIImage imageNamed:@"tab5.png"], nil]; for (int i = 0; i<5; i++) { UIImageView *image = (UIImageView*)[tabbar viewWithTag:10+i]; [image setImage:[tabImageArray objectAtIndex:i]]; } }
So, just bypass the tabImageArray in each View controller. Then you can use it.
I also work on iOS 7.
mialkan Oct 08 '13 at 12:43
source share