Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hide and show left navigation bar button on demand in iOS-7

I added my left navigation bar button using the storyboard. but I want it to hide when I first load the screen. And then in response to something else, I want it to show. The navigation bar has a method for hiding the back button. But there is no method for hiding/showing the left button. Is there a simple way for doing this? Or do I have to use two methods: the hiding method creates an empty button and the showing method creates the correct button? The button in question is just the Add template that iOS provides (which makes it easy to just use the one in the storyboard than to create my own).

like image 348
learner Avatar asked Aug 01 '14 19:08

learner


People also ask

How do I hide navigation bar on Iphone?

Way 1: Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.

How do I hide the navigation bar button?

The navigation bar is pinned by default. If you want to view files or use apps in full screen, double-tap the Show and hide button to hide the navigation bar.


2 Answers

Here is how I solved it

-(void) hideAndDisableRightNavigationItem
{
    [self.navigationItem.rightBarButtonItem setTintColor:[UIColor clearColor]];
    [self.navigationItem.rightBarButtonItem setEnabled:NO];
}

-(void) showAndEnableRightNavigationItem
{
    [self.navigationItem.rightBarButtonItem setTintColor:[UIColor blackColor]];
    [self.navigationItem.rightBarButtonItem setEnabled:YES];
}
like image 120
learner Avatar answered Nov 03 '22 23:11

learner


Swift version of @learner answer

func hideAndDisableRightNavigationItem (){
  self.navigationItem.rightBarButtonItem?.enabled = false
  self.navigationItem.rightBarButtonItem?.tintColor = UIColor.clearColor()
}

func showAndEnableRightNavigationItem(){
   self.navigationItem.rightBarButtonItem?.enabled = true
   self.navigationItem.rightBarButtonItem?.tintColor = UIColor. blackColor()
}
like image 41
LHIOUI Avatar answered Nov 03 '22 21:11

LHIOUI