Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationController transparency?

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.

like image 287
user3492165 Avatar asked Apr 05 '14 20:04

user3492165


People also ask

How to make navigation bar background transparent in swift?

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 .

What is translucent navigation bar?

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

How do I change the color of my UINavigationBar?

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.


1 Answers

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];
like image 190
Krivoblotsky Avatar answered Sep 30 '22 20:09

Krivoblotsky