gpt4 book ai didi

iphone - 如何删除 UITabBarItem 下方的空间?

转载 作者:可可西里 更新时间:2023-11-01 03:03:50 27 4
gpt4 key购买 nike

我创建了一个 tabBar 并在其中设置了图像,但是它在 tabBarItem 下方留下了太多空间。我怎样才能删除它?

这是我的 tabBar 而不是现在显示

enter image description here

我想这样显示

enter image description here

显示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"];

最佳答案

正如 Vytis 在 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);

你必须写下面几行代码

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

关于iphone - 如何删除 UITabBarItem 下方的空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17357409/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com