我在我的应用中使用标签栏控件,并希望在我的某个标签中使用默认搜索图标。我正在编程标签栏但我无法找到一个属性,我可以在其中指定我在Apple文档中找到的UITabBarSystemItemSearch项目。以下是我的标签栏代码
CouponsViewController *coupons = [[CouponsViewController alloc] init];
UINavigationController *couponsNavigationController = [[UINavigationController alloc] initWithRootViewController:coupons];
couponsNavigationController.tabBarItem.title = @"Coupons";
couponsNavigationController.navigationBar.tintColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.1];
[coupons release];
SettingsViewController *settings = [[SettingsViewController alloc] init];
UINavigationController *settingsNavigationController = [[UINavigationController alloc] initWithRootViewController:settings];
settingsNavigationController.tabBarItem.title = @"Settings";
settingsNavigationController.navigationBar.tintColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.1];
[settings release];
ProfileViewController *profile = [[ProfileViewController alloc] init];
UINavigationController *profileNavigationController = [[UINavigationController alloc] initWithRootViewController:profile];
profileNavigationController.tabBarItem.title = @"Profile";
profileNavigationController.tabBarItem.image = [UIImage imageNamed:@"profileImg.png"];
profileNavigationController.navigationBar.tintColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.1];
[profile release];
[tabBarController setViewControllers:[NSArray arrayWithObjects:loyaltyNavigationController,searchNavigationController,couponsNavigationController,settingsNavigationController,profileNavigationController,nil] animated:NO];
tabBarController.delegate=self;
tabBarController.selectedIndex=0;
[window addSubview:tabBarController.view];
答案 0 :(得分:10)
在您放入标签栏的UIViewController子类中执行此代码。最好在视图控制器的初始化方法中完成:
- (id) init
{
self.title = @"search";
self.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch
tag:0];
return self;
}