我在一个UITabBar上有一个UIViewController,我已经设置了UITabBar委托,这就是我如何在UIViewController方法中设置UITabBar
// 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)那么我就有了像这样的委托方法
#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委托。
发布于 2014-03-27 22:44:59
您可以轻松地编写如下代码:
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]];发布于 2014-03-27 22:29:43
我想下面的所有链接都会对您有所帮助,而且就委托而言,当您将UITabBarItem设置为每个标记,然后操作您的条件时,就可以这样做了。
通过代码向UITabBar和UITabBar添加一个表项(注意:我不想实现TabBarController )
如何以编程方式在iOS中添加UITabBarItem的标识符类型?
教程如何以编程方式构建制表符栏
https://stackoverflow.com/questions/22700354
复制相似问题