user2452016
user2452016

Reputation:

How to remove space below the UITabBarItem?

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

enter image description here

And I want to display it like this

enter image description here

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

Answers (2)

Manish Agrawal
Manish Agrawal

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 and finishedUnselectedImage 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

V-Xtreme
V-Xtreme

Reputation: 7333

I think you should use image insect in the xib for this like ,enter image description here

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

Related Questions