Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

objective c - UINavigationBar with rounded corners

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?

like image 839
Eyal Avatar asked Apr 20 '12 16:04

Eyal


1 Answers

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

like image 74
Ashley Mills Avatar answered Oct 24 '22 10:10

Ashley Mills