这个问题解决了有些时候了,终于知道了办法,先看个代码
1 2 3 4 5 6 7 8
| [[UITabBar appearance] setTintColor:[UIColor colorWithRed:0.0 green:176.0/255.0 blue:226.0/255.0 alpha:1.0]];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor lightGrayColor], UITextAttributeTextColor, nil] forState:UIControlStateNormal];
|
UITabbar有个setTintColor这个方法,可以理解为,高亮的时候,或者点击后的颜色设置。
UITabBarItem有个setTitleTextAttributes的方法,是用来设置字体的颜色。
我这里是在viewDidLoad添加的。
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| UITabBar *tabBar = self.tabBarController.tabBar; [tabBar setTintColor:[UIColor colorWithRed:0.0 green:176.0/255.0 blue:226.0/255.0 alpha:1.0]]; tabBar.selectedImageTintColor = [UIColor clearColor]; UITabBarItem *item = [tabBar.items objectAtIndex:0]; NSString *homePath = [[NSBundle mainBundle] pathForResource:@"btn_home_highlight" ofType:@"png"]; if(item.tag == 1) { [item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor lightGrayColor], UITextAttributeTextColor, nil] forState:UIControlStateNormal]; item.selectedImage = [UIImage imageWithContentsOfFile:homePath]; }
|