美文网首页
2020-09-25

2020-09-25

作者: 驰马奥 | 来源:发表于2020-09-25 00:43 被阅读0次

    随笔

    uiview 绘制圆角

    方法一

        CAShapeLayer *shapeLayer = [CAShapeLayer layer];

       UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];

        shapeLayer.path= path.CGPath;

        self.layer.mask= shapeLayer;

    方法二

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

        CAShapeLayer*maskLayer = [[CAShapeLayeralloc]init];

        maskLayer.frame=self.bounds;

        maskLayer.path= maskPath.CGPath;

        self.layer.mask= maskLayer;

    方法三

        CAShapeLayer *maskLayer = [CAShapeLayer layer];

        maskLayer.frame=self.bounds;

        CAShapeLayer*borderLayer = [CAShapeLayerlayer];

        borderLayer.frame=self.bounds;

        borderLayer.lineWidth= borderWidth;

        borderLayer.strokeColor= borderColor.CGColor;

        borderLayer.fillColor = [UIColor clearColor].CGColor;

        UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:cornerRadius];

        maskLayer.path= bezierPath.CGPath;

        borderLayer.path= bezierPath.CGPath;

        [self.layer insertSublayer:borderLayer atIndex:0];

        [self.layersetMask:maskLayer];

    方法四

        CAShapeLayer *layer = [[CAShapeLayer alloc] init];

        CGMutablePathRef pathRef = CGPathCreateMutable();

        CGRectbounds =CGRectInset(self.frame,0,0);

        CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));

        CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), cornerRadius);

        CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMinY(bounds), cornerRadius);

        CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMinX(bounds), CGRectGetMinY(bounds), cornerRadius);

        CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMinX(bounds), CGRectGetMaxY(bounds), cornerRadius);

        layer.path= pathRef;

        CFRelease(pathRef);

        layer.strokeColor= [borderColorCGColor];

        layer.fillColor= backgroudColor.CGColor;

        UIView*roundView = [[UIViewalloc]initWithFrame:bounds];

        [roundView.layerinsertSublayer:layeratIndex:0];

        roundView.backgroundColor = UIColor.clearColor;

    相关文章

      网友评论

          本文标题:2020-09-25

          本文链接:https://www.haomeiwen.com/subject/fidxuktx.html