8

我在其中创建了一个tabBar并设置了图像,但它在tabBarItem. 我怎样才能删除它?

这不是我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];

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

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

为了在项目上设置图像,我使用了这段代码

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

2 回答 2

19

正如 Vytis 在这里的回答中所说:

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

要使用全高图像(49px)finishedSelectedImagefinishedUnselectedImage您需要设置这些图像插图:

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);
于 2013-06-28T05:09:22.360 回答
9

我认为您应该为此在 xib 中使用图像昆虫,在此处输入图像描述

对于您的要求,顶部应该是一些正值,底部应该是一些相同的负值。如果您以编程方式添加了标签栏,那么您可以参考 Wills 答案

于 2013-06-28T05:10:07.517 回答