更改UITabBarItem图像的颜色

时间:2015-06-23 20:10:15

标签: icons uitabbar uitabbaritem selected swift2

我很难尝试更改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 Beta Swift 2.0

1 个答案:

答案 0 :(得分:0)

已经回答here,但简而言之,点击您想要更改的标签栏项目,您可以在故事板中添加新的运行时属性,这将在选择时更改整个项目(图像和文本)。