gpt4 book ai didi

ipad - 将 UITabBarItems 添加到 UITabBar

转载 作者:行者123 更新时间:2023-12-02 08:56:43 25 4
gpt4 key购买 nike

我希望任何人都可以解释我如何做到这一点:

我有一个TabBar和两个TabBarItems,如何将项目附加到TabBar。我没有通过 IB 执行此操作,因为 TabBar 只适合屏幕,因为项目应该位于左侧。

这就是我构建它们的方式:

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

最佳答案

您不能直接在选项卡栏中设置选项卡栏项目。相反,您可以将选项卡栏项目分配给选项卡栏 Controller 包含的每个 View Controller 的 tabBarItem 属性。然后,当您将 View Controller 添加到选项卡栏 Controller 时,选项卡栏 Controller 将为您管理选项卡栏项目的显示。

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

关于ipad - 将 UITabBarItems 添加到 UITabBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4326928/

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