內存的消耗最少,並且渲染最快的顯示圓角

 


OC

/**
 使用CAShapeLayer和UIBezierPath設置圓角
 內存的消耗最少,並且渲染快速
 */

- (void)cutCircleLayer:(UIView *)sender {
    
    // 切半圓
    UIBezierPath *maskPath =
    [UIBezierPath bezierPathWithRoundedRect:sender.bounds cornerRadius:20];
    
    // 切 圓
//    UIBezierPath *maskPath =
//    [UIBezierPath bezierPathWithRoundedRect:sender.bounds
//                          byRoundingCorners:UIRectCornerAllCorners
//                                cornerRadii:sender.bounds.size];
    
    /**
     UIRectCornerTopLeft
     UIRectCornerTopRight
     UIRectCornerBottomLeft
     UIRectCornerBottomRight
     UIRectCornerAllCorners
     */
    
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    
    //設置大小
    maskLayer.frame = sender.bounds;
    
    //設置圖形樣子
    maskLayer.path = maskPath.CGPath;
    
    sender.layer.mask = maskLayer;
}spa


    Swift

    /**
     使用CAShapeLayer和UIBezierPath設置圓角
     內存的消耗最少,並且渲染快速
     */
    func cutCircleLayer(sender: UIView) {
        
        // 切半圓
        let maskPath = UIBezierPath(roundedRect: sender.bounds, cornerRadius: 20);
        
        
        // 切 圓
        //let maskPath = UIBezierPath(roundedRect: sender.bounds, byRoundingCorners: UIRectCorner.AllCorners, cornerRadii: sender.bounds.size);
        
        /**
         TopLeft
         TopRight
         BottomLeft
         BottomRight
         AllCorners
         */
        
        let maskLayer = CAShapeLayer();
        
        //設置大小
        maskLayer.frame = sender.bounds;
        
        //設置圖形樣子
        maskLayer.path = maskPath.CGPath;
        
        sender.layer.mask = maskLayer;
        
    }內存

 


OC版本Demo演示點此下載.get

 

Swift版本Demo演示點此下載it


學自: FFIB渲染

相關文章
相關標籤/搜索