UITabbar图像和标题在ipad中不对齐

问题描述 投票:2回答:2

我正在使用Tabbarcontroller的应用程序(有两个选项卡)在iphone上一切正常但在ipad上两个选项卡都在屏幕的中心

我想在每个标签的中心显示标题和图像(考虑标签宽度是屏幕的一半)

在搜索这些时,我遇到了UIEdgeInsetsMake

Adjust iOS TabBar item title to the centre of it,但没有帮助。

我不明白在哪里放这个代码。我试着将它放在FirstViewController中然后在app delegate中(逐个),但对我来说没有任何作用

这是我的appDelegate代码:

FirstViewController *firstVC = [[FirstViewController alloc] init];
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:firstVC];
//navController1.title = @"First Tab";
navController1.tabBarItem.image = [UIImage imageNamed:@"first.png"];

SecondViewController *secondVC = [[SecondViewController alloc] init];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:secondVC];
navController2.title = @"Second Tab";
navController2.tabBarItem.image = [UIImage imageNamed:@"second.png"];

NSArray *array = [[NSArray alloc] initWithObjects:navController1,navController2, nil];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
 tabBarController.tabBarItem.imageInsets = UIEdgeInsetsMake(0, -50, 0, 50);

tabBarController.viewControllers = array;

[self.window setRootViewController:tabBarController];

self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;

有人可以帮忙吗?

ios ipad uitabbarcontroller uiedgeinsets
2个回答
2
投票

参考this回答我建议你这样做

1获取屏幕宽度并将其除以您拥有的标签栏项目数

2一旦分割,通过qazxsw poi将平均值分配给qazxsw poi

setItemWidth

5
投票

您应该将此代码放在UITabBarController的viewWillLayoutSubviews中

UITabBar
© www.soinside.com 2019 - 2024. All rights reserved.