我可以使用 this answer 更改标签栏的事件颜色
我的问题是我不知道如何更改好友和搜索选项卡等非事件选项卡。我想将其更改为红色。 我搜索了这么多并决定询问,因为我找不到任何解决方案。请耐心等待,因为我是使用 swift 进行 ios 开发的新手。
最佳答案
我会发布我为获得我想要实现的目标所做的工作。这也可能在未来帮助像我这样的大佬。
首先我为每个图标创建了两个图像
然后点击Assets.xcassets
文件添加New Image Set
确保绿色图标 Render As
设置为 Original Image
因为这将是我们标签栏的非事件颜色图标。这是示例属性的示例屏幕截图
通过设置Home Item标签栏图标。请注意
System Item => Custom
Selected Image => Home_w//Name of the home white icon
Title => Home
Image=> Home_g//Name of the Inactive tabbar item in my case are sets to green icons
最终在 AppDelegate.swift
中覆盖我们标签栏项目的标题颜色。请注意我使用了 UIColor_Hex_Swift
用于十六进制 UIColor。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let color:UIColor = UIColor(rgba: "#026a34") //UIColor(hexString:"026a34")
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: color], forState: .Normal)
// then if StateSelected should be different, you should add this code
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.whiteColor()], forState: .Selected)
return true
}
Out put(白色的是选中的图片,绿色的是非事件图片)
关于ios - 更改选项卡项的非事件颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34671332/