如何更改 iOS7 中的未选定的 tabbaritem 颜色
展开全部
此代码在 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"];
希望帮到楼主
[[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"];
希望帮到楼主
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询