I want the default height as seen in the Storyboard image when adding the bar programmatically. Any idea how to get it? Here is the code I use to add a UITabBarController
to my app.
- (void)setCustomTabBar
{
//TODO: Fix TabBar height
UITabBarController *tabBarController = [[UITabBarController alloc] init];
TimelineVC *tvc = [[TimelineVC alloc] initWithNibName:@"TimelineVC" bundle:nil];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:tvc];
TimelineVC *tvc2 = [[TimelineVC alloc] initWithNibName:@"TimelineVC" bundle:nil];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:tvc2];
tvc2.showFriends = true;
NotificationVC *nvc = [[NotificationVC alloc] initWithNibName:@"NotificationVC" bundle:nil];
nav3 = [[UINavigationController alloc] initWithRootViewController:nvc];
ProfileVC *pvc = [[ProfileVC alloc] initWithNibName:@"ProfileVC" bundle:nil];
UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:pvc];
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
[[UITabBar appearance] setShadowImage:nil];
[tabBarController setViewControllers:@[nav1, nav2, nav3, nav4]];
tabBarController.selectedIndex = 0;
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat tabBarWidth = screenRect.size.width/4;
[[UITabBar appearance] setBackgroundImage:[AppDelegate imageFromColor:[UIColor darkGrayColor] forSize:CGSizeMake(screenRect.size.width, 49) withCornerRadius:0]];
[[UITabBar appearance] setSelectionIndicatorImage:[AppDelegate imageFromColor:[UIColor colorWithRed:26/255.0 green:163/255.0 blue:133/255.0 alpha:1] forSize:CGSizeMake(tabBarWidth, 49) withCornerRadius:0]];
tabBarController.tabBar.translucent = NO;
UIImage *normalImage, *selectedImages;
normalImage =[UIImage imageNamed:@"TimeLineIcon"];
selectedImages = [UIImage imageNamed:@"TimeLineIcon"];
UIImage *normalImage2, *selectedImages2;
normalImage2 =[UIImage imageNamed:@"FriendsIcon"];
selectedImages2 = [UIImage imageNamed:@"FriendsIcon"];
UIImage *normalImage3, *selectedImages3;
normalImage3 =[UIImage imageNamed:@"NotificationIcon"];
selectedImages3 = [UIImage imageNamed:@"NotificationIcon"];
UIImage *normalImage4, *selectedImages4;
normalImage4 =[UIImage imageNamed:@"ProfileIcon"];
selectedImages4 = [UIImage imageNamed:@"ProfileIcon"];
//TODO: FOR LOOP
nav1.tabBarItem.selectedImage = [normalImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
nav1.tabBarItem.image = [selectedImages imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
nav1.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
nav2.tabBarItem.selectedImage = [normalImage2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
nav2.tabBarItem.image = [selectedImages2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
nav2.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
nav3.tabBarItem.selectedImage = [normalImage3 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
nav3.tabBarItem.image = [selectedImages3 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
nav3.tabBarItem.badgeValue = @"1";
nav3.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
nav4.tabBarItem.selectedImage = [normalImage4 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
nav4.tabBarItem.image = [selectedImages4 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
nav4.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
self.window.rootViewController = tabBarController;
[self.window addSubview:tabBarController.view];
[self enableSupportKit];
}
This helped me. Hope it helps.