如何删除UITabBarItem下面的空格?

时间:2013-06-28 04:52:45

标签: iphone ios tabbar uitabbaritem

我创建了一个tabBar并在其中设置了图片,但它在tabBarItem下留下了太多空间。我该如何删除?

这是我tabBar而不是现在显示

enter image description here

我想像这样显示它

enter image description here

显示标签栏

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];

对于tabBar背景图片,我使用了此代码

UIImage* tabBarBackground = [UIImage imageNamed:@"tabbarimg1.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];

并设置img项目我已使用此代码

//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"];

2 个答案:

答案 0 :(得分:17)

Vytis在their answer here中说:

  

UIBarItem上有一个属性(UIBarButton项继承自此   class)imageInsets

     

finishedSelectedImage和使用全高图像(49像素)   finishedUnselectedImage您需要设置这些图像插入内容:

     

tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);

您必须编写以下代码行

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);

答案 1 :(得分:9)

我认为你应该在xib中使用image insect,enter image description here

对于您的要求top应该是一些正值,而bottom应该是一些相同的负值。如果您以编程方式添加了选项卡栏,则可以参考Wills答案