2012-12-28 69 views
-2

我不得不只圆整UIView的上角。我试图使用以下代码:UIView圆角

UIBezierPath *maskEmailPath = [UIBezierPath bezierPathWithRoundedRect:self.emailandAccessView.bounds byRoundingCorners:UIRectCornerBottomLeft cornerRadii:CGSizeMake(10.0, 10.0)]; 
CAShapeLayer *maskEmailLayer = [CAShapeLayer layer]; 
maskEmailLayer.frame = self.myview.bounds; 
maskEmailLayer.path = maskEmailPath.CGPath; 
self.myview.layer.mask = maskEmailLayer; 

但它隐藏了该视图中的所有内容。谁能帮帮我吗。

+0

尽量不设置掩模层的帧成为你视图的边界的 – wattson12

+0

可能重复的[制作的UIView轮的特定角(http://stackoverflow.com/questions/14067897/make-specific -corners-的-UIView的圆) –

回答

1

这就是你如何做到的。

CALayer *capa = self.view.layer; 
    CGRect bounds = capa.bounds; 
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:bounds 
               byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) 
                 cornerRadii:CGSizeMake(5.0, 5.0)]; 

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

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