2012-12-28 71 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;