Transparency UINavigationController?

I'm trying to make the navigation bar become 100% transparent, so the UINavigationButtonItem elements are only visible, and the background (usually white) should show a background image.

I tried

HomeNavigationController *navBar = [[HomeNavigationController alloc] initWithRootViewController:self.myViewController]; [navBar.navigationBar setBarTintColor:[UIColor clearColor]]; [navBar.navigationBar setTranslucent:YES]; 

although they don’t work.

EDIT:

Using

 [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; self.navigationController.navigationBar.shadowImage = [UIImage new]; self.navigationController.navigationBar.translucent = YES; self.navigationController.view.backgroundColor = [UIColor clearColor]; 

I see that it worked as expected, however the elements are now also invisible.


FINALEDIT: Ah, the code above works, just make sure that you do not apply any other appearance changes without testing first!

Code that actually does what is intended:

 [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; 

Alternatively, you can set a transparent image, but that makes sense. You will need the rest of the code shown in the original board if you don't want the line to represent the border.

+6
source share
1 answer

There is a trick. Just set the transparent image to the navigation bar screen.

 UIImage *fakeImage = [UIImage imageNamed:@"transparentImage"]; [navigationBar setBackgroundImage:fakeImage forBarMetrics:UIBarMetricsDefault]; 

OR

 [navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; 
+6
source

All Articles