【问题标题】:How to remove space below the UITabBarItem?如何删除 UITabBarItem 下面的空间?
【发布时间】:2023-04-02 12:35:01
【问题描述】:

我创建了一个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"];

【问题讨论】:

  • 你的标签栏在哪里?正如您所写的“这是我的标签栏,而不是现在显示”
  • 是否有问题,因为我添加了我的图片,它显示了一些其他图像,如 GTA 副城图像......奇怪......
  • 嘿@Kane 不要显示你的标签栏......
  • @Will 现在完成检查现在仍然不明白当我第一次添加这张图片时出现什么问题,当时我的第一张图片显示了一些多面性的人,他们发表演讲,第二张图片显示 Vicecity 而不是我的图片所以我必须删除图像并重新插入它..
  • @BhaveshNai 现在检查...

标签: iphone ios tabbar uitabbaritem


【解决方案1】:

正如 Vytis 在 their answer here 中所说:

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

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

【讨论】:

  • 当您复制另一个人的话时,您需要明确指出并链接到原始答案。我在上面已经这样做了,但请确保您在未来提供正确的归属。
【解决方案2】:

我认为您应该为此在 xib 中使用图像昆虫,

根据您的要求,顶部应该是一些正值,底部应该是一些相同的负值。如果您以编程方式添加了标签栏,则可以参考遗嘱答案

【讨论】:

  • 我认为这种方式更好 b/c 你可以在界面生成器上编辑它,顺便说一句它仍然可以在 xcode 7 上工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-14
  • 1970-01-01
  • 2021-07-20
  • 1970-01-01
相关资源
最近更新 更多