Make a UIBarButtonItem disappear using swift IOS

前端 未结 15 2206
慢半拍i
慢半拍i 2020-12-10 23:31

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

@IBOutlet var creeLigueBouton: UIBarButtonItem!

and I want to make it disappea

15条回答
  •  醉话见心
    2020-12-11 00:30

    First way:

    Just set .title to ""

    Second way:

    Just call updateToolBar() whenever you want to show/hide the creeLigueBouton.

    func updateToolBar() {
        var barItems: [UIBarButtonItem] = []
    
        if condition != true {
            // Make it appear
            barItems.append(creeLigueBouton)
        }
    
        barItems.append(anotherButton)
    
        myToolBar.setItems(barItems, animated: true)
    
        myToolBar.setNeedsLayout()
    }
    

提交回复
热议问题