将Uitabbaritems添加到Uitabbar
-
29-09-2019 - |
题
我希望任何人都可以解释我该怎么做:
我有一个塔巴尔和两个tabaritems,我如何将这些物品放到塔巴尔。我不是通过IB这样做的,因为塔巴尔仅适合屏幕,因为这些项目应在左侧。
那就是我的建造方式:
tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
tabBarController2 = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
tabBarController.tabBar.frame = CGRectMake(0, 974, 384, 50);
tabBarController2.tabBar.frame = CGRectMake(384, 974, 384, 50);
UITabBarItem *tbi1 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:0];
UITabBarItem *tbi2 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:1];
解决方案
您不会直接在标签栏中设置标签栏项目。相反,您将标签栏项目分配给 tabBarItem
标签栏控制器包含的每个视图控制器的属性。然后,当您将视图控制器添加到标签栏控制器中时,标签栏控制器将为您管理选项卡栏项目的显示。
UITabBarController * tabBarController = [[UITabBarController alloc] init];
UIViewController * viewController1 = [[YourViewController alloc] init];
UIViewController * viewController2 = [[YourOtherViewController alloc] init];
viewController1.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:0];
viewController2.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:1];
tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
不隶属于 StackOverflow