0

I would like to create a UINavigationBar that doesn't has colored background.

I tried

 self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];

and

 self.navigationController.navigationBar.backgroundColor = nil;

but couldn't solve the problem. I also tried to set the same color for the nav bar that I use for the self.view.backgroundColor, but I couldn't override the original one. (I'm using Storyboard maybe that causes the problem, but not sure, because I can manipulate the tintColor with code.)

rihekopo
  • 3,241
  • 4
  • 34
  • 63
  • Dupe http://stackoverflow.com/questions/2315862/make-uinavigationbar-transparent – Sonny Saluja Jan 20 '15 at 00:39
  • You can't set navigationBar to clear with navigationItem. You can do this by setting navigationBar hidden, and add a custom button on top-left or top-right as your navigationItem. – simalone Jan 20 '15 at 05:27

2 Answers2

1
self.navigationController.navigationBarHidden = NO;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new]
                             forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    self.navigationController.navigationBar.translucent = YES;

UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
//[backButton setImage:[UIImage imageNamed:@"you_back_image"] forState:UIControlStateNormal]; this is the image you would use as a back image
[backButton setTitle:@"back" forState:UIControlStateNormal];
[backButton sizeToFit];
[backButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem* backBarButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = backBarButton;

and then write the method goBack which depends on the fact if you presented or pushed the current ViewController.

- (void)goBack {
//[self dismissViewControllerAnimated:YES] 
//[self.navigationController popViewControllerAnimated:YES];
}
trdavidson
  • 1,051
  • 12
  • 25
0

try this one in appDelegates didFinishLaunchingWithOptions method it clears navigation bar's background color

[[UINavigationBar appearance]setBarTintColor:[UIColor clearColor]];