首页 > 移动平台 > 详细

iOS使用mask切割不规则图案

时间:2019-02-25 17:08:25      阅读:370      评论:0      收藏:0      [点我收藏+]

 

 

起点,终点要闭合:

CGPathAddQuadCurveToPoint(path, NULL, viewSize.width * 0.5, viewSize.height, viewSize.width, viewSize.height * 0.9); 这个方法画弧线
/**
 根据几何知识规则 生成不规则图形
 */
-(void)makeContents3{
    //生成path
    CGMutablePathRef path =CGPathCreateMutable();
    
    CGSize viewSize = self.bounds.size;
    
    CGPathMoveToPoint(path, NULL, 0, viewSize.height * 0.9);//左边直线下点
    
    CGPathAddQuadCurveToPoint(path, NULL, viewSize.width * 0.5, viewSize.height, viewSize.width, viewSize.height * 0.9);
    CGPathAddLineToPoint(path, NULL, viewSize.width, 0);
    CGPathAddLineToPoint(path, NULL, 0, 0);
    CGPathAddLineToPoint(path, NULL, 0, viewSize.height * 0.9); // 形成闭环
    
    
    CAShapeLayer *maskLayer= [CAShapeLayer layer];
    
    //        maskLayer.path=[UIBezierPath bezierPathWithRoundedRect:self.indicateView.bounds cornerRadius:30].CGPath;
    
    maskLayer.path=path;
    
    maskLayer.fillColor=[UIColor blackColor].CGColor;//填充色
    maskLayer.strokeColor=[UIColor redColor].CGColor;
    maskLayer.frame=self.bounds;
    maskLayer.contentsCenter=CGRectMake(0.5, 0.5, 0.1, 0.1);
    //按比例放大 不变形
    maskLayer.contentsScale=[UIScreen mainScreen].scale;
    
    //
    CALayer * contentLayer=[CALayer layer];
    contentLayer.mask=maskLayer;
    contentLayer.frame=self.bounds;
    
    self.layer.mask = maskLayer;
    
}

 

iOS使用mask切割不规则图案

原文:https://www.cnblogs.com/tufei7/p/10431758.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!