0

I have created UITabBarController programatically with 5 tabs like,

UIViewController *profileVC = [[UIViewController alloc] init];
UINavigationController *profileNC=[[UINavigationController alloc]initWithRootViewController:profileVC];

UIImage *profileImage = getImage(@"tab1", NO);
UIImage *profileImageSel = getImage(@"tab1_s", NO);
profileImage = [profileImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
profileImageSel = [profileImageSel imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
profileNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:profileImage selectedImage:profileImageSel];

... etc.

UITabBarController *tabBarVC = [[UITabBarController alloc]init];
    tabBarVC.tabBar.backgroundColor = [UIColor whiteColor];
[tabBarVC setViewControllers:@[profileNC,...]];
    tabBarVC.view.autoresizingMask=(UIViewAutoresizingFlexibleHeight);
[self.navigationController presentViewController:tabBarVC animated:YES completion:^{
 }];

But its displaying the line at the top and having the space at the bottom

enter image description here

How to fix this issue? pls help.

Surfer
  • 1,370
  • 3
  • 19
  • 34

2 Answers2

1

Check the size of your images, they might be smaller than the hight of the tab bar. To remove the top and bottom lines you can try something like this in the viewDidLoad: method:

  self.tabBar.backgroundImage = [UIImage new];
  [[UITabBar appearance] setShadowImage:[UIImage new]];

I am assuming the lines you see are really the original background of the tab bar, which is a semi-transparent background, if you use bigger images, they should fill up all the bar but you might still see a small border line at the top, with the code above you can remove any background and especially the top line.

Juan de la Torre
  • 1,297
  • 9
  • 19
  • my image size is 128x88 in 2x . What image dimension i have to use? – Surfer Dec 18 '14 at 04:16
  • I believe they get stretched maintaining their aspect ratio if they are bigger than the max size, for @2x is 96x64. Check this out https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/IconMatrix.html#//apple_ref/doc/uid/TP40006556-CH27-SW1 – Juan de la Torre Dec 18 '14 at 04:32
  • I have some horizontal padding, I have set the label.layer.opaque=NO; and it solved the problem. – Arpit B Parekh Aug 31 '15 at 10:37
0

try this, hope it can work for you.

viewController.navigationController.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -12);
Avineet Gupta
  • 586
  • 10
  • 21