Make a UIBarButtonItem disappear using swift IOS

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

    // Nice answer haiLong, I think as an extension this is more convenient.
    
    extension UIBarButtonItem {
        var isHidden: Bool {
            get {
                return !isEnabled && tintColor == .clear
            }
            set {
                tintColor = newValue ? .clear : nil
                isEnabled = !newValue
            }
        }
    }
    

    EDIT: Removed forced unwrapping and fixed enabled value.

提交回复
热议问题