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?
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:
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