gpt4 book ai didi

ios - 更改默认 "Not Selected"UITabBarItem 图像颜色

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:26:02 25 4
gpt4 key购买 nike

我们如何更改 UITabBarItem 中图标的“未选中”或未突出显示状态?

我尝试设置 UITabBarItem.appearance().setTitleTextAttributes(:) 但它只会更改文本颜色。

有什么想法吗?

enter image description here

最佳答案

如果你想在 iOS 7 及更高版本中更改默认值,你必须实际使用不同的图标(使用你喜欢的未选中选项卡的颜色)并设置文本的颜色。您可以应用此调整,而不是创建两组图标:

// set the selected colors
[self.tabBar setTintColor:[UIColor whiteColor]];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];


UIColor * unselectedColor = [UIColor colorWithRed:184/255.0f green:224/255.0f blue:242/255.0f alpha:1.0f];

// set color of unselected text
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:unselectedColor, NSForegroundColorAttributeName, nil]
forState:UIControlStateNormal];

// generate a tinted unselected image based on image passed via the storyboard
for(UITabBarItem *item in self.tabBar.items) {
// use the UIImage category code for the imageWithColor: method
item.image = [[item.selectedImage imageWithColor:unselectedColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}

Source.

关于ios - 更改默认 "Not Selected"UITabBarItem 图像颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30664500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com