1

在应用程序中,我将 UINavigationBar 子类化,并且作为我的 TitleView,我正在设置(在视图控制器中)自定义 UIView

[self.playButton setBackgroundColor:[UIColor yellowColor]];
[self.navigationItem setTitleView:self.playButton];

此视图 (playButton) 的底部边缘应该是弯曲的。不仅是角落,机器人整个底边。为了达到这种效果,我正在使用以下代码:

CAShapeLayer *maskLayer = [CAShapeLayer layer];
UIBezierPath *path = [[UIBezierPath alloc] init];

[path addCurveToPoint:CGPointMake(self.playButton.frame.size.width, self.playButton.frame.size.height)  controlPoint1:CGPointMake(0, self.playButton.frame.size.height) controlPoint2:CGPointMake(self.playButton.frame.size.width, 60)];
maskLayer.path = path.CGPath;
self.playButton.layer.mask = maskLayer;

但在那段代码之后,我的 UIView (playButton) 消失了!这是应用 UIView 弯曲底部边缘的正确方法吗?

它应该看起来像这样:http: //i.imgur.com/51UIQsE.png

4

2 回答 2

0
CAShapeLayer *maskLayer = [CAShapeLayer layer];
[maskLayer setFrame:self.playButton.bounds];
UIBezierPath *path = [UIBezierPath bezierPath];

[path addArcWithCenter:CGPointMake(self.playButton.center.x, -36.0) radius:65.5 startAngle:0 endAngle:2*M_PI clockwise:YES];


//[path closePath];
maskLayer.path = path.CGPath;
self.playButton.layer.mask = maskLayer;
于 2013-05-15T06:42:51.340 回答
0

解决方案:

-(void)roundCorners:(UIRectCorner)corner radius:(float)radius
{   
    _cornerRadius = radius;
    _corner = corner;
    [self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect {
    // Drawing code
    [super drawRect:rect];

    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:_corner cornerRadii:CGSizeMake(_cornerRadius, _cornerRadius)];

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

    self.layer.mask = maskLayer;
}
于 2015-01-28T23:05:25.467 回答