gpt4 book ai didi

ios - UITabBar 的 TabBarItems

转载 作者:行者123 更新时间:2023-11-28 22:11:56 25 4
gpt4 key购买 nike

我在 UIViewController 上有一个 UITabBar,我已经设置了 UITabBar 委托(delegate),这就是我在 中设置 UITabBar 的方式code>viewDidLoad: 方法

// Load UITabBar for FindModels View & call tabBar delegates
findModelsTabBar = [[UITabBar alloc] init];
findModelsTabBar.delegate = self; // This sets up tabbardelegate method

[findModelsTabBar setTranslucent:NO];
findModelsTabBar.backgroundColor = [UIColor lightGrayColor];
findModelsTabBar.frame = CGRectMake(0.0, screenRectTabBar.size.height - 110, screenRectTabBar.size.width, 45.0);
[[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:colorController.lgRed/255.0 green:colorController.lgGreen/255.0 blue:colorController.lgBlue/255.0 alpha:1.0]];

[self.view insertSubview:findModelsTabBar aboveSubview:self.tableView]; // add tabBar to the mainView (appears at the bottom of the screen)

然后我有这样的委托(delegate)方法

#pragma TabBar delegate
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
switch (item.tag) {
case 0:
{
NSLog(@"0");
}
break;
case 1:
{
NSLog(@"1");
}
break;
case 2:
{
NSLog(@"2");
FindModelsViewController *findModelsViewController = [[FindModelsViewController alloc] initWithNibName:@"FindModelsViewController" bundle:nil];

// Sets the back button for the new view that loads (this overrides the usual parentview name with "Back")
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:nil action:nil];

[self.navigationController pushViewController:findModelsViewController animated:YES];

// Set Delegates so you can get the data back
[findModelsViewController setDelegate:self];
}
break;
default:
break;
}
}

我想知道如何创建带有图像的 UITabBar 项目,并在单击时调用该 tabBar 委托(delegate)。

最佳答案

您可以轻松地编写一些代码,例如:

UITabBarItem * item0 = [[UITabBarItem alloc] initWithTitle:@"Page 1"
image:[UIImage imageNamed:@"page1_image_normal"]
selectedImage:[UIImage imageNamed:@"page1_image_selected"]];
[item0 setTag:0];

UITabBarItem * item1 = [[UITabBarItem alloc] initWithTitle:@"Page 2"
image:[UIImage imageNamed:@"page2_image_normal"]
selectedImage:[UIImage imageNamed:@"page2_image_selected"]];
[item1 setTag:1];

UITabBarItem * item2 = [[UITabBarItem alloc] initWithTitle:@"Page 3"
image:[UIImage imageNamed:@"page3_image_normal"]
selectedImage:[UIImage imageNamed:@"page3_image_selected"]];
[item2 setTag:2];

[findModelsTabBar setItems:@[item0, item1, item2]];

关于ios - UITabBar 的 TabBarItems,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22700354/

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