我有一个tabBarController和我设置的图标,但我无法选择未选择的图标成功。它接缝我只选择一个1图标和一个选定的颜色即可。
如何拍摄颜色或为未选择的状态设置单独的图标? 我没有成功设置图标和所选图标。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Set the status bar to light style
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
UITabBarController *tabBarController = (UITabBarController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"TabBar"];
UITabBar *tabBar = tabBarController.tabBar;
NSLog(@"%@", tabBar.items);
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
//UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
//UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
tabBarItem1.image = [UIImage imageNamed:@"IconTabBarFolder"];
tabBarItem1.selectedImage = [UIImage imageNamed:@"IconTabBarFolder:Highlighted"];
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Medium" size:10.0f], NSForegroundColorAttributeName : [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1] } forState:UIControlStateNormal];
return YES;
}
答案 0 :(得分:0)
您可以使用以下代码为UITabbarItem
添加图片:
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"stores222.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"home-icon-inactive.png"]];
iOS7更新: 请使用此代码:
UIImage *aImage = [UIImage imageNamed:@"a"];
aImage = [aImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *inaImage = [UIImage imageNamed:@"ina"];
inaImage = [inaImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.aController.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"title" image:inaImage selectedImage:aImage];