Reputation:
I have created a tabBar
and set image in it, but it leaves too much space below the tabBarItem
. How can I remove that?
This is my tabBar
than displaying right now
And I want to display it like this
To display Tabbar
firstVC = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
secondVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
thirdVC = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
forthVC = [[ForthViewController alloc] initWithNibName:@"ForthViewController" bundle:nil];
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
NSArray *viewControllersArray = [[NSArray alloc] initWithObjects:firstVC,secondVC,thirdVC,forthVC, nil];
self.tabController = [[UITabBarController alloc] init];
[self.tabController setViewControllers:viewControllersArray animated:NO];
[self.window addSubview:self.tabController.view];
//self.tabController.selectedIndex = 1;
self.tabController.delegate = self;
self.window.rootViewController = self.tabController;
[self.window makeKeyAndVisible];
For tabBar background image i have used this code
UIImage* tabBarBackground = [UIImage imageNamed:@"tabbarimg1.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
And for set the imge at item i have used this code
//used to set the tabBarItem images
[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"home_tab"] withFinishedUnselectedImage:[UIImage imageNamed:@"home_tab"]];
//Set the badge on tabBarItem
[self.tabBarItem setBadgeValue:@"15"];
Upvotes: 8
Views: 4845
Reputation: 11037
As Vytis says in their answer here:
There is a property on UIBarItem (UIBarButton item inherits from this class)
imageInsets
.To use full height images (49px) for
finishedSelectedImage
andfinishedUnselectedImage
you need to set these image insets:
tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
you have to write the following lines of code
item0.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0); item1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0); item2.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0); item2.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
Upvotes: 19
Reputation: 7333
I think you should use image insect in the xib for this like ,
for your requirement top should be some positive value and bottom should be some same negative value . If you have added the tab bar programmatically then you can refer the Wills answer
Upvotes: 9