ios - 更改选项卡项的非事件颜色

标签 ios iphone swift uiviewcontroller

我可以使用 this answer 更改标签栏的事件颜色

chage color inactive tab bar

我的问题是我不知道如何更改好友和搜索选项卡等非事件选项卡。我想将其更改为红色。 我搜索了这么多并决定询问,因为我找不到任何解决方案。请耐心等待,因为我是使用 swift 进行 ios 开发的新手。

最佳答案

我会发布我为获得我想要实现的目标所做的工作。这也可能在未来帮助像我这样的大佬。

首先我为每个图标创建了两个图像

主页图标、好友图标和搜索图标各有白色和绿色 inactive tabbar icon

然后点击Assets.xcassets文件添加New Image Set New Image Set

确保绿色图标 Render As 设置为 Original Image 因为这将是我们标签栏的非事件颜色图标。这是示例属性的示例屏幕截图 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

enter image description here

最终在 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(白色的是选中的图片,绿色的是非事件图片)

Home active Friends active search active

关于ios - 更改选项卡项的非事件颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34671332/

相关文章:

ios - 如何在 iOS 中获得一个不会过期的缓存?

ios - 调用了 UICollectionView cellForItemAtIndexPath 但数据源为空

swift - 以编程方式填充 STPPaymentCardTextField

ios - XCTest:点击 navigationItem 返回按钮

objective-c - iOS : I can't write my file

iphone - 如何从 iOS App 检测不安全的 wifi 网络

ios - swift中performSelector的替代品是什么?

iphone - iOS——使用宏转发一堆消息?

ios - 调用中缺少参数参数

ios 在数据加载和隐藏原型(prototype)单元格时触发 TableView 中的事件指示器