I am trying to get my navigation bar to become 100% transparent, so that the UINavigationButtonItems are only visible and the background (normally white) should show the background image.
I tried
HomeNavigationController *navBar = [[HomeNavigationController alloc] initWithRootViewController:self.myViewController];
[navBar.navigationBar setBarTintColor:[UIColor clearColor]];
[navBar.navigationBar setTranslucent:YES];
although neither appear to 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 can see that it worked as expected, however the items are now also invisible.
FINALEDIT: Ah the code above DOES work, just ensure you do not apply any other changes to the appearance without testing first !
The code that actually does what is intended:
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
Alternatively you can set a transparent image, but this makes more sense. You will need the rest of the code shown in the original edit if you want no line representing the border.
You need to do three things to make a navigation bar transparent. Set background image to non-nil empty image ( UIImage() ). Set shadow image to non-nil empty image ( UIImage() ). Set isTranslucent to true .
Translucent or partially transparent is when the colour can be seen but the background behind the object is also slightly visible through it. For this we use. background-color: #FFFFFF; opacity: 0.5; filter: alpha(opacity=50);
Open the project's storyboard file. Select the UINavigationBar from your UINavigationController scene. In the Attributes Inspector pane turn on these Appearances: “Standard”, “Compact”, “Scroll Edge”, and “Compact Scroll Edge”. For all four appearances, set the “Background” to “System Red Color”, for example.
There is a trick. Just set transparent image to the navigation bar background.
UIImage *fakeImage = [UIImage imageNamed:@"transparentImage"];
[navigationBar setBackgroundImage:fakeImage forBarMetrics:UIBarMetricsDefault];
OR
[navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With