如何更改为iOS的7 tabBarItems文本和图标的颜色
1个回答
展开全部
1. 有两件事情你需要做的是: 1)如果你想自定义的TabBar本身,你需要设置barTintColor为tabBarController: // this will generate a black tab bar
tabBarController.tabBar.barTintColor = [UIColor blackColor];
// this will give selected icons and text your apps tint color
tabBarController.tabBar.tintColor = appTintColor; // appTintColor is a UIColor *
2)设置tabBarItem文本外观要覆盖每一个状态:[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],
NSForegroundColorAttributeName : appTintColor
} forState:UIControlStateSelected];
// doing this results in an easier to read unselected state then the default iOS 7 one
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],
NSForegroundColorAttributeName : [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1]
} forState:UIControlStateNormal];
2. 这个工作要在着色的标签栏不活跃的项目UITabBarItem *item = [self.tabBar.items objectAtIndex:1];
//这里你需要用你想要的颜色的图标,因为它会被渲染,因为它是item.image = [[UIImage imageNamed:@"unselected.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//这个图标选中的标签,它会得到有色定义见self.tabBar.tintColor
item.selectedImage = [UIImage imageNamed:@"selected.png"];
3. 使用self.tabBarController.tabBar.barStyle = UIBarStyleBlack;使标签栏黑色
4. 埃德的答案是完美的,但补充一点。 的TabBar是默认的半透明使用TabBar下受到的观点的颜色(即的ViewController的视图的颜色影响的TabBar外观)。 所以我设置下面的代码不会受到影响。self.tabBarController.tabBar.translucent = false;
连同Ed的这里的答案是代码了。self.tabBarController.tabBar.barTintColor = [UIColor blackColor];
self.tabBarController.tabBar.translucent = false;
self.tabBarController.tabBar.tintColor = [UIColor blueColor];
5. 你试试吧for (UITabBarItem *item in self.tabBarController.tabBar.items) {
item.image = [[UIImage imageNamed:@"youimage.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
nil] forState:UIControlStateNormal];
item.selectedImage = [UIImage imageNamed:@"youimage.png"];
tabBarController.tabBar.barTintColor = [UIColor blackColor];
// this will give selected icons and text your apps tint color
tabBarController.tabBar.tintColor = appTintColor; // appTintColor is a UIColor *
2)设置tabBarItem文本外观要覆盖每一个状态:[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],
NSForegroundColorAttributeName : appTintColor
} forState:UIControlStateSelected];
// doing this results in an easier to read unselected state then the default iOS 7 one
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],
NSForegroundColorAttributeName : [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1]
} forState:UIControlStateNormal];
2. 这个工作要在着色的标签栏不活跃的项目UITabBarItem *item = [self.tabBar.items objectAtIndex:1];
//这里你需要用你想要的颜色的图标,因为它会被渲染,因为它是item.image = [[UIImage imageNamed:@"unselected.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//这个图标选中的标签,它会得到有色定义见self.tabBar.tintColor
item.selectedImage = [UIImage imageNamed:@"selected.png"];
3. 使用self.tabBarController.tabBar.barStyle = UIBarStyleBlack;使标签栏黑色
4. 埃德的答案是完美的,但补充一点。 的TabBar是默认的半透明使用TabBar下受到的观点的颜色(即的ViewController的视图的颜色影响的TabBar外观)。 所以我设置下面的代码不会受到影响。self.tabBarController.tabBar.translucent = false;
连同Ed的这里的答案是代码了。self.tabBarController.tabBar.barTintColor = [UIColor blackColor];
self.tabBarController.tabBar.translucent = false;
self.tabBarController.tabBar.tintColor = [UIColor blueColor];
5. 你试试吧for (UITabBarItem *item in self.tabBarController.tabBar.items) {
item.image = [[UIImage imageNamed:@"youimage.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
nil] forState:UIControlStateNormal];
item.selectedImage = [UIImage imageNamed:@"youimage.png"];
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询