gpt4 book ai didi

ios - 在 viewcontroller 之上放置一个 Tabbar Controller

转载 作者:行者123 更新时间:2023-11-28 20:06:23 26 4
gpt4 key购买 nike

how to connect them. 我如何将 TABBAR 控件放在 View 控件的顶部。默认情况下它位于底部我该如何放置它..?

使用下面的代码来做:

 UIImage* tabBarBackground = [UIImage imageNamed:@"footer-bg.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance]setSelectionIndicatorImage:[UIImage imageNamed:@"footer-hover-bg.png"]];

if(IS_IOS_7)
{
[[appDelegate.tabBarController tabBar] setSelectionIndicatorImage:[UIImage imageNamed:@"footer-hover-bg.png"]];
[[UITabBar appearance] setTintColor:[UIColor blackColor]];
}
appDelegate.tabBarController.tabBar.frame = CGRectMake(0, 20, 320, 50);
appDelegate.tabBarController.delegate=self;

UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, -20, 320, 600)];

viewControllers = [[NSMutableArray alloc] init];

MainViewController *view1 = [[MainViewController alloc] init];
UINavigationController *nav1=[[UINavigationController alloc]initWithRootViewController:view1];
[viewControllers addObject:nav1];

ViewController1 *view2 = [[ViewController1 alloc] init];
UINavigationController *nav2=[[UINavigationController alloc]initWithRootViewController:view2];
[viewControllers addObject:nav2];

[appDelegate.tabBarController setViewControllers:viewControllers];

appDelegate.tabBarController.tabBarController.view.frame=CGRectMake(0, 0, 320, 480);
[view addSubview:appDelegate.tabBarController.view];

[self.view addSubview:view];

UITabBarItem *tabBarItem1 = [appDelegate.tabBarController.tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [appDelegate.tabBarController.tabBar.items objectAtIndex:1];


[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:[arraySelectedImages objectAtIndex:0]] withFinishedUnselectedImage:[UIImage imageNamed:[arrayUnselectedImages objectAtIndex:0]]];
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:[arraySelectedImages objectAtIndex:1]] withFinishedUnselectedImage:[UIImage imageNamed:[arrayUnselectedImages objectAtIndex:1]]];

我如何使用 Storyboard做同样的事情?

最佳答案

首先添加一个 UIViewController,然后添加 UITabBar,如果您使用自动布局,则添加约束。

enter image description here

不要忘记连接委托(delegate)。

希望对您有所帮助。

关于ios - 在 viewcontroller 之上放置一个 Tabbar Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21984216/

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