我正在使用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;
有人可以帮忙吗?
您应该将此代码放在UITabBarController的viewWillLayoutSubviews中
UITabBar