5

I want to make my navigation bar a one with rounded corners (the top left and right)

I found this code that make it happen:

CALayer *capa = [self.navigationController navigationBar].layer;
[capa setShadowColor: [[UIColor blackColor] CGColor]];
[capa setShadowOpacity:0.85f];
[capa setShadowOffset: CGSizeMake(0.0f, 1.5f)];
[capa setShadowRadius:2.0f];  
[capa setShouldRasterize:YES];


//Round
CGRect bounds = capa.bounds;
bounds.size.height += 10.0f;    //I'm reserving enough room for the shadow
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:bounds 
                                               byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
                                                     cornerRadii:CGSizeMake(10.0, 10.0)];

CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = bounds;
maskLayer.path = maskPath.CGPath;

[capa addSublayer:maskLayer];
capa.mask = maskLayer;

But it has one problem, now that the nab bar doesn't have the corner edge, it is transparent in thous corners and I can see the view that behind it.
I don't want it to be transparent I want to put some black color there.
Anybody know how to do that?

Eyal
  • 10,777
  • 18
  • 78
  • 130

1 Answers1

5

Assuming this is a top level navigation controller, something like this should work for you:

self.window.backgroundColor = [UIColor blackColor];

Just stick that in your application:didFinishLaunchingWithOptions:

Failing that, just use a nav bar image with black corners:

enter image description here

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
  • thanks but this is not a good solution for me, a lot of time I have different views behind the navbar. – Eyal Apr 20 '12 at 17:08
  • > Failing that, just use a nav bar image with black corners - YES I think this is a better solution :) also very easy to do in photoshop and more efficient than drawing rounded corners on screen. – Eyal Apr 26 '12 at 08:35
  • BTW this is a great navigation bar image can I use it in my app? – Eyal May 15 '12 at 09:23
  • thanks :) not to be rude but do u maybe have the psd file (assuming it was done with Photoshop)? – Eyal May 15 '12 at 11:47
  • Sorry - a) I made it in Pixelmator, and b) I only have the png – Ashley Mills May 15 '12 at 15:05