我正在尝试设置 UITabBarItem 的图标,但它不起作用。顺便说一句,我正在为这个项目使用 Xcode 5 Beta。
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
{
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
UIImage *tabBarBackground = [UIImage imageNamed:@"tabbar.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_selected.png"]];
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
}
return YES;
}
我试图在选中和未选中时使图标变为白色,但在未选中状态下它们保持灰色。
编辑
我试过这样做,但现在我收到错误“未使用的表达式结果”
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
tabBarItem1.title = @"Home";
UIImage *graph = [UIImage imageNamed:@"graph.png"];
[tabBarItem1 initWithTitle:(NSString *)@"HELLO" image:(UIImage *)graph selectedImage:(UIImage *)graph];