How do I hide/show the right button in the Navigation Bar

前端 未结 18 2013
后悔当初
后悔当初 2020-12-12 19:25

I need to hide the right button in the Navigation Bar, then unhide it after the user selects some options.

Unfortunately, the following doesn\'t work:



        
18条回答
  •  悲&欢浪女
    2020-12-12 20:02

    In swift 4 I has a trick to show / hide right or left button:

    Step 1: Create a IBOutlet button in view controller:

    @IBOutlet var navigationItemButton: UIBarButtonItem!
    

    Step 2: Create Hide button function:

    func hideNavigationButton() {
        navigationItemButton.isEnabled = false
        navigationItemButton.tintColor = UIColor.clear
    }
    

    Step 3: Create Show button function:

    func showNavigationButton() {
        navigationItemButton.isEnabled = true
        navigationItemButton.tintColor = UIColor.white
    }
    

    Step 4: Just call the functions that you want, use hideNavigationButton() to hide, and showNavigationButton() to show the button.

    Regards!

提交回复
热议问题