How do I show/hide a UIBarButtonItem?

前端 未结 30 2320
执念已碎
执念已碎 2020-11-28 01:18

I created a toolbar in IB with several buttons. I would like to be able to hide/show one of the buttons depending on the state of the data in the main window.

30条回答
  •  忘掉有多难
    2020-11-28 01:50

    I used IBOutlets in my project. So my solution was:

    @IBOutlet weak var addBarButton: UIBarButtonItem!
    
    addBarButton.enabled = false
    addBarButton.tintColor = UIColor.clearColor()
    

    And when you'll need to show this bar again, just set reversed properties.

    In Swift 3 instead enable use isEnable property.

提交回复
热议问题