您的位置:首页 > 移动开发 > IOS开发

如何更改 iOS7 中的未选定的 tabbaritem 颜色

2015-11-23 09:51 316 查看
此代码在 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];

如你所设置的前景色。
影响也非选定 tabbar 图标:
[[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"];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: