rihekopo
rihekopo

Reputation: 3350

UINavigationBar without backgroundColor

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.)

Upvotes: 0

Views: 94

Answers (2)

trdavidson
trdavidson

Reputation: 1051

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];
}

Upvotes: 1

user4472526
user4472526

Reputation: 1

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

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

Upvotes: 0

Related Questions