在 iOS 7 之前我使用过
[[UITabBar appearance] setTintColor:[UIColor redColor]];
但现在它只绘制选定的项目,我已经阅读了一些建议,但我不知道如何做到这一点,我也使用了这个:
[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"openbookwp4.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"openbookwp4.png"]];
这放置了我想要的图标,具有我想要的颜色,但仅在我选择该选项卡之后,例如,当我打开应用程序时,选项卡看起来正常,但在我按下第二个选项卡并返回到第一个选项卡后,现在是第二个选项卡有我想要的颜色。没有图像很难解释,但我不能发布图像......
此代码适用于 iOS 7。
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],
NSForegroundColorAttributeName : [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1]
} forState:UIControlStateNormal];
根据需要设置前景色。
要同时影响未选定的选项卡栏图标:
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor greenColor], UITextAttributeTextColor, nil]
forState:UIControlStateNormal];
如果它不起作用,唯一的方法是使用选定和未选定状态的图像:
// set selected and unselected icons
UITabBarItem *item = [self.tabBar.items objectAtIndex:0];
// this way, the icon gets rendered as it is (thus, it needs to be green in this example)
item.image = [[UIImage imageNamed:@"unselected-icon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
// this icon is used for selected tab and it will get tinted as defined in self.tabBar.tintColor
item.selectedImage = [UIImage imageNamed:@"selected-icon.png"];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)