gpt4 book ai didi

ios - 如何更改 iOS 7 中选定的标签栏项目颜色?

转载 作者:可可西里 更新时间:2023-11-01 06:18:04 26 4
gpt4 key购买 nike

我用的是 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"];

关于ios - 如何更改 iOS 7 中选定的标签栏项目颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19662017/

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