【发布时间】:2016-04-12 19:10:01
【问题描述】:
我可以使用 this answer 更改标签栏的活动颜色
我的问题是我不知道如何更改不活动的朋友和搜索选项卡。我想将其更改为红色。 我进行了很多搜索并决定询问,因为我找不到任何解决方案。请多多包涵,因为我是使用 swift 进行 ios 开发的新手。
【问题讨论】:
标签: ios iphone swift uiviewcontroller
我可以使用 this answer 更改标签栏的活动颜色
我的问题是我不知道如何更改不活动的朋友和搜索选项卡。我想将其更改为红色。 我进行了很多搜索并决定询问,因为我找不到任何解决方案。请多多包涵,因为我是使用 swift 进行 ios 开发的新手。
【问题讨论】:
标签: ios iphone swift uiviewcontroller
我将发布我所做的事情以实现我想要实现的目标。这也可能对将来像我这样的大人物有所帮助。
首先我为每个图标创建了两个图像
然后点击Assets.xcassets文件添加New Image Set
确保绿色图标 Render As 设置为 Original Image 因为这将是我们标签栏的非活动颜色图标 strong>.这是示例属性的示例屏幕截图
通过设置 Home Item 标签栏 Icon。请注意
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
}
输出(白色的是选中的图片,绿色的是非活动图片)
【讨论】:
从 iOS 10 开始,您可以使用它来更改选项卡项目的颜色(您必须将图像呈现为模板):
UITabBar.appearance().tintColor = .blue
UITabBar.appearance().unselectedItemTintColor = .gray
【讨论】:
试试这个
self.tabBar.tintColor=[UIColor whiteColor];
【讨论】:
this 可能是您希望搜索具体解决方案的最佳链接。
【讨论】: