我正在使用Tabbarcontroller的应用程序上工作(有两个选项卡)在iphone上一切正常,但在ipad上,两个选项卡都位于屏幕中央
我想在每个标签的中心显示标题和图像(考虑标签的宽度是屏幕的一半)
在搜索这些内容时,我遇到了UIEdgeInsetsMake
将iOS TabBar项目标题调整到它的中心,但是对此没有帮助。
我不知道将这段代码放在哪里。我试图将其放在FirstViewController中,然后放在应用程序委托中(一个接一个),但对我没有任何作用
这是我的appDelegete代码:
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;
有人可以帮忙吗?
关于这个答案,我建议你这样做
1获取屏幕宽度并将其除以您拥有的选项卡栏项目的数量
2一旦将平均值除以setItemWidth
到UITabBar
CGRect screenSize = [[UIScreen mainScreen] applicationFrame];
int count = [array count];
float width = screenSize.size.width/count;
[[UITabBar appearance] setItemWidth:width];
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句