To do this, you need to create your own tab bar for the Sub class UITabBarController .
TabBarController.h file:
@interface TabBarController : UITabBarController<UITabBarControllerDelegate> { UITabBarController *tabController; UIImageView *img1; UIImageView *img2; UIImageView *img3; UIImageView *img4; }
.m file
- (void)viewDidLoad { [self loadTabView]; //[self viewWillAppear:YES]; [super viewDidLoad]; } - (void) loadTabView { tabController = [[UITabBarController alloc] init]; tabController.delegate = self; tabController.tabBar.backgroundColor = [UIColor clearColor]; //set offset for tabbar items images. int topOffset = 6; int bottomOffset = 6; UIEdgeInsets imageInset = UIEdgeInsetsMake(topOffset, 0, -bottomOffset, 0); [self.view addSubview:tabController.view]; } // reset the background image in custom tabbar. - (void) setTabBarBackground { UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"btnbg.png"]]; img.frame = CGRectOffset(img.frame, 0, 1); img.frame = CGRectMake(img.frame.origin.x, img.frame.origin.y-1, img.frame.size.width, img.frame.size.height); [tabController.tabBar insertSubview:img atIndex:0]; [img release]; } // reset the background image in custom tabbar. - (void) resetTabBar : (NSString *) tabid { [img1 removeFromSuperview]; NSLog(@"tab id - %@",tabid); switch ([tabid intValue]) { case 0: img1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab-1.jpg"]]; break; case 1: img1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab-2.jpg"]]; break; case 2: img1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab-3.jpg"]]; break; case 3: img1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab-4.jpg"]]; break; case 4: img1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab-5.jpg"]]; break; default: break; } img1.frame = CGRectOffset(img1.frame, 0, 1); [tabController.tabBar insertSubview:img1 atIndex:0]; [tabController.tabBar bringSubviewToFront:img1]; [img1 release]; } // here push View controllers - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { }
Hope this gives you an idea.
source share