0

I'm trying to set a faded darker background to a navigation bar, as you can see on the image below.

enter image description here

I've tried with this code but it's not exactly what I expect.

UINavigationBar.appearance().backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.4)

I've found this topic, but without suitable answer:

Shows a faded gray color view through iOS 7 Navigation bar of a UISplitViewController

Any idea will be appreciated.

EDIT 6 oct 2015 : If somebody needs to know how to perform that

For Swift users : - in particular viewcontroller : i use :

 self.navigationController!.navigationBar.setBackgroundImage(UIImage(named: "fadedimage.png"), forBarMetrics: .Default)

in the main NavigationController (to apply that to the all navigationBar) i use :

UINavigationBar.appearance().setBackgroundImage(UIImage(named: "fadedimage.png"), forBarMetrics: .Default)
Community
  • 1
  • 1
Hugo75
  • 249
  • 3
  • 15

1 Answers1

1

This might not be the correct way, but you can achieve the same by using a custom image.

Donwload a transparent image from internet, I named it as transparent.png

and set the navigation bar background image:

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"transaprent.png" ] forBarMetrics:UIBarMetricsDefault];

[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.0f]];

This gives the result: enter image description here

Later you can apply the shadow effect for the navigation bar.

Edit:

I donwloaded a custom shadow transparent png image, and applied it using above code.

enter image description here

You can still improve this with a better custom image as per your requirements.

Here is the image I used:

enter image description here

To remove the bottom border that appears on navbar, use this code:

    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109
  • thanks Mr.T, i put the code in Swift in my main post. – Hugo75 Oct 06 '15 at 19:43
  • in the top where we can see the battery, the carrier, the time, it's still normal. the background image is not applied. Have you an idea why ? – Hugo75 Oct 06 '15 at 19:45
  • do you mean the font for the battery and carrier should changee with the background image ? – Teja Nandamuri Oct 06 '15 at 19:56
  • On your example battery and carrier have the good black background as expected. In mine , i see the map on the background. – Hugo75 Oct 06 '15 at 20:01