uitabbaritemsをuitabbarに追加します
-
29-09-2019 - |
質問
誰でもこれを行う方法を説明できることを願っています:
Tabbarと2つのTabbaritemsがあります。アイテムをTabbarにatatchするにはどうすればよいですか。アイテムは左側にある必要があるため、Tabbarのみが画面に適合しているため、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