gpt4 book ai didi

iphone - 以编程方式创建TABBAR

转载 作者:行者123 更新时间:2023-12-03 20:18:11 25 4
gpt4 key购买 nike

我以这种方式以编程方式创建了选项卡栏

UITabBarController  *tabBarController = [[UITabBarController alloc] init];


contacts *vc1 = [[contacts alloc]init];

vc1.tabBarItem.image=[UIImage imageNamed:@"contacts.png"];

search* vc2 = [[search alloc] init];

vc2.tabBarItem.image=[UIImage imageNamed:@"search.png"];

a1* vc3 = [[a1 alloc] init];

a2 *vc4 = [[a2 alloc] init];

a3 *vc5 = [[a3 alloc] init];


NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2,vc3,vc4,vc5, nil];
tabBarController.viewControllers = controllers;

[self.view addSubview:detailNavCont];
// Add the tab bar controller's current view as a subview of the window
[self.view addSubview:tabBarController.view];

我想要完成的是,我想将图像分配给选项卡栏,首先我在前两个选项卡上尝试,显示一个蓝色 block 而不是图像。其次,当我们通过界面构建​​器创建标签栏时,有自定义标签栏项目,例如,联系人,搜索,书签,撰写等。

所以,如果我想将联系人或搜索图像分配给我的选项卡栏项目,这看起来像IB中的项目,我该怎么做??

问候

最佳答案

尝试这样的事情

tabBars = [[UITabBarController alloc] init];
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:4];

HomeTabViewController *ptr_homeTab;
ptr_homeTab = [[HomeTabViewController alloc]initWithNibName:@"HomeTabViewController" bundle:nil];
UINavigationController *homeNavBar=[[UINavigationController alloc]initWithRootViewController:ptr_homeTab];
homeNavBar.tabBarItem.title=@"Home";
homeNavBar.tabBarItem.image=[UIImage imageNamed:@"home.png"];
[ptr_homeTab release];

myHospitalviewController=[[MyHospitalViewController alloc]initWithNibName:@"MyHospitalViewController" bundle:nil];
UINavigationController *myHospitalNavBar=[[UINavigationController alloc]initWithRootViewController:myHospitalviewController];
myHospitalNavBar.title=@"My Hospital";
myHospitalNavBar.tabBarItem.image=[UIImage imageNamed:@"myhospital.png"];
[myHospitalviewController release];

viewController = [[TreatMentiViewController alloc]initWithNibName:@"TreatMentiViewController" bundle:nil];
UINavigationController *hospitalNavBar=[[UINavigationController alloc]initWithRootViewController:viewController];
hospitalNavBar.tabBarItem.title=@"Hospital";
hospitalNavBar.tabBarItem.image=[UIImage imageNamed:@"hospital.png"];
[viewController release];

PersonalMedicineViewController *ptr_PersonalMedicine = [[PersonalMedicineViewController alloc] initWithNibName:@"PersonalMedicineViewController" bundle:nil];
UINavigationController *managerNavBar=[[UINavigationController alloc]initWithRootViewController:ptr_PersonalMedicine];
managerNavBar.tabBarItem.title=@"Manager";
managerNavBar.tabBarItem.image=[UIImage imageNamed:@"manager.png"];
[ptr_PersonalMedicine release];

[localViewControllersArray addObject:homeNavBar];
[localViewControllersArray addObject:hospitalNavBar];
[localViewControllersArray addObject:myHospitalNavBar];
[localViewControllersArray addObject:managerNavBar];

[homeNavBar release];
[hospitalNavBar release];
[myHospitalNavBar release];
[managerNavBar release];

tabBars.viewControllers = localViewControllersArray;
tabBars.view.autoresizingMask==(UIViewAutoresizingFlexibleHeight);

[localViewControllersArray release];

[window addSubview:tabBars.view];

关于iphone - 以编程方式创建TABBAR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3923465/

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