Make a UIBarButtonItem disappear using swift IOS

Clément Bisaillon picture Clément Bisaillon · Aug 25, 2014 · Viewed 34k times · Source

I have an IBOutlet that I have linked to from the storyboard

@IBOutlet var creeLigueBouton: UIBarButtonItem!

and I want to make it disappear if a condition is true

if(condition == true)
{
    // Make it disappear
}

Answer

haiLong picture haiLong · Oct 21, 2015

Use the property enabled and tintColor

    let barButtonItem:UIBarButtonItem? = nil

    if isHidden{
        barButtonItem?.enabled      = false
        barButtonItem?.tintColor    = UIColor.clearColor()
    }else{
        barButtonItem?.enabled      = true
        barButtonItem?.tintColor    = nil
    }