【问题标题】:Changing UITabBarItem image's color更改 UITabBarItem 图像的颜色
【发布时间】:2015-06-23 20:10:15
【问题描述】:

我很难更改UITabBarItem 图标的颜色。我使用下面的代码来初始化所有参数:

// Settings Tab
    tabBarController?.tabBar.translucent = false
    tabBarController?.tabBar.barTintColor = dark_color

    let titoli:[String] = ["Feed","Categorie","Info"]
    for (var i:Int=0; i<titoli.count; i++){
        let tab:UITabBarItem? = tabBarController?.tabBar.items![i] as UITabBarItem?
        tab?.image = UIImage(named: titoli[i])
        tab?.title = titoli[i]
        tab?.setTitleTextAttributes(NSDictionary(object: UIColor.whiteColor(), forKey: NSForegroundColorAttributeName) as? [String:AnyObject], forState: UIControlState.Selected)
        tab?.setTitleTextAttributes(NSDictionary(object: UIColor(red: 0, green: 0, blue: 0, alpha: 0.6), forKey: NSForegroundColorAttributeName) as? [String:AnyObject], forState: UIControlState.Normal)
    }

我在这里遗漏了什么吗? 仅供参考:只玩 XCode BetaSwift 2.0

【问题讨论】:

  • 会发生什么?出了什么问题?

标签: icons uitabbar uitabbaritem selected swift2


【解决方案1】:

已经回答here,但简而言之,单击您要更改的标签栏项目,您可以在情节提要中添加一个新的运行时属性,该属性将在选中时更改整个项目(图像和文本)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-04
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多