我有一個UIViewController
一個UITabBar
,我已經設置了UITabBar
委託,這是我如何設置UITabBar我的viewDidLoad:
方法內TabBarItems爲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委託時...
任何幫助,將不勝感激。
這工作完全謝謝!如果我只使用一個UITabBarItem有沒有一種方法來正確或左對齊它? – HurkNburkS
據我所知,沒有這種方式。你可以使用iOS 7 SDK中定義的UITabBarItemPositioning來做一些技巧,但它會居中或填充標籤欄。 – ismailgulek