Make a UIBarButtonItem disappear using swift IOS

前端 未结 15 2200
慢半拍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:18

    It is quite late to reply but looking for an answer for my problem I found this topic. The marked answer did not help me, but I managed to solve my problem thanks to @haiLong's answer. My solution works for all types of bar buttons... I think. Add this to your ViewController and use as needed.

    var tintColorsOfBarButtons = [UIBarButtonItem: UIColor]()
    
        func hideUIBarButtonItem(button: UIBarButtonItem) {
            if button.tintColor != UIColor.clear {
                tintColorsOfBarButtons[button] = button.tintColor
                button.tintColor = UIColor.clear
                button.isEnabled = false
            }
        }
    
        func showUIBarButtonItem(button: UIBarButtonItem) {
            if tintColorsOfBarButtons[button] != nil {
                button.tintColor = tintColorsOfBarButtons[button]
            }
            button.isEnabled = true
        }
    

    I hope it saves some time to other developers :)

提交回复
热议问题