how to disable a navigation bar button item in iOS

前端 未结 16 1279
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-01 09:54

I have created a navigation controller. In the second view (which is pushed), I have some webservice call and placing a overlay view and setting

self.view.use

相关标签:
16条回答
  • 2021-01-01 10:20

    This code should work on Swift 4.2

    self.navigationItem.rightBarButtonItem?.isEnabled = false
    

    The above code will disable the button. To enable it switch the boolean to true

    0 讨论(0)
  • 2021-01-01 10:24

    Just disable your UINavigationController view and navigation bar interaction:

    self.navigationController.navigationBar.userInteractionEnabled = NO;
    self.navigationController.view.userInteractionEnabled = NO;
    

    And enable it when you need it back:

    self.navigationController.navigationBar.userInteractionEnabled = YES;
    self.navigationController.view.userInteractionEnabled = YES;
    
    0 讨论(0)
  • 2021-01-01 10:24
    var menuBtn = new UIButton(UIButtonType.Custom);
    menuBtn.Frame = new CGRect(x: 0.0, y: 0.0, width: 20, height: 20);
    menuBtn.SetImage(new UIImage("filter"), UIControlState.Normal);
    
    menuBtn.Alpha = 0.05f;   //to set the Alpha
    
    menuBtn.Enabled = false;
    

    tested on Mvvmcross Xamarin.iOS only

    0 讨论(0)
  • 2021-01-01 10:25

    Try this

    Recommended

    self.navigationItem.leftBarButtonItem.enabled = NO;
    
    self.navigationItem.rightBarButtonItem.enabled = NO;
    

    Or Simply Disable by

    on Edge case

    self.view.window.userInteractionEnabled = NO;
    

    Update: Recently Apple doesn't allow the back button to enable / disable. Instead of that we can hide it.

    self.navigationItem.hidesBackButton = YES;
    
    0 讨论(0)
提交回复
热议问题