How do I show/hide a UIBarButtonItem?

前端 未结 30 2257
执念已碎
执念已碎 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:57

    Try in Swift, don't update the tintColor if you have some design for your UIBarButtonItem like font size in AppDelegate, it will totally change the appearance of your button when showing up.

    In case of a text button, changing title can let your button 'disappear'.

    if WANT_TO_SHOW {
        myBarButtonItem.enabled = true
        myBarButtonItem.title = "BUTTON_NAME"
    }else{
        myBarButtonItem.enabled = false
        myBarButtonItem.title = ""
    }
    

提交回复
热议问题