点击按钮时更改UIBarButtonItem tintColor?

时间:2015-06-17 14:11:04

标签: ios objective-c swift

我的UIBarButtonItem定义如下:

let cardNavButton: UIBarButtonItem = UIBarButtonItem(image: UIImage(named: "card")!, style: UIBarButtonItemStyle.Bordered, target: self, action: self.headerCardButtonSelector)
self.navigationItem.rightBarButtonItem = cardNavButton
cardNavButton.tintColor = UIColor.whiteColor()

当用户点击按钮时,其颜色会发生变化。如何定义用户点按按钮时显示的颜色?

此按钮中显示的图像有多种颜色,但只显示一种颜色。我怎么能改变它?

2 个答案:

答案 0 :(得分:0)

您可以使用自定义UIButton创建UIBarButtonItem,并为状态设置正确的颜色。

            let customButton: UIButton = UIButton()
            //customize yout custom button
            let cardNavButton: UIBarButtonItem = UIBarButtonItem(customView: customButton)
            self.navigationItem.rightBarButtonItem = cardNavButton

答案 1 :(得分:0)

假设“s”是正确的十六进制值字符串,例如绿色“00ff00”,点击按钮时使用此代码:

/Users/guy/.rvm/gems/ruby-2.3.0/gems/writeexcel-1.0.5/lib/writeexcel/chart.rb
:79:in 'factory': undefined method 'new' for nil:NilClass (NoMethodError)
        from /Users/guy/.rvm/gems/ruby-2.3.0/gems/writeexcel-1.0.5/lib/writee
xcel/workbook.rb:334:in 'add_chart'
        from excelGraph.rb:18:in '<main>'