简体   繁体   English

UINavigationBar圆了两个角落

[英]UINavigationBar Rounded Two Corners

I want to round the top right and top left of the UINavigationBar. 我想围绕UINavigationBar的右上角和左上角。

I know that there are functions for changing the views corner radius, but is it possible to do something similar to the standard UINavigationBar? 我知道有更改视角半径的功能,但是可以做一些类似于标准UINavigationBar的操作吗?

If you don't know what I'm talking about, check out this: 如果您不知道我在说什么,请查看以下内容:

Thanks! 谢谢!

the following code works for me (tested on iOS5). 以下代码适用于我(在iOS5上测试)。 The following code rounds the top left/right corners of the main navigation bar. 以下代码围绕主导航栏的左上角/右上角。 Additionally, it adds a shadow to it: 此外,它增加了一个阴影:

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;

最好的方法是覆盖UINavigationBar中的drawRect并使用自定义图像。

You might find this helpful. 您可能会觉得这很有帮助。 Maybe you could also do some kind of masking with CoreAnim/Image? 也许你也可以用CoreAnim / Image进行某种掩饰? I'm not very knowledgeable about the Core* family... 我不太了解Core *系列......

http://foobarpig.com/iphone/uinavigationbar-with-solid-color-or-image-background.html http://foobarpig.com/iphone/uinavigationbar-with-solid-color-or-image-background.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM