美文网首页
IOS 给cell 中的view设置部分圆角

IOS 给cell 中的view设置部分圆角

作者: 夜未殇 | 来源:发表于2017-12-06 14:18 被阅读0次
    - (void)layoutSublayersOfLayer:(CALayer *)layer {
        //使用masonry加
        [_chatBackView layoutIfNeeded];
        
        //防止复用重复添加layer
        for (CALayer *layer in _chatBackView.layer.sublayers) {
            if ([layer.name isEqualToString:@"lit"]) {
                [layer removeFromSuperlayer];
            }
        }
        
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_chatBackView.bounds byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
    
        CAShapeLayer *shapeLayer = [CAShapeLayer layer];
        shapeLayer = [CAShapeLayer layer];
        shapeLayer.path = maskPath.CGPath;
        _chatBackView.layer.mask = shapeLayer;
    
        CAShapeLayer *borderLayer=[CAShapeLayer layer];
        borderLayer.path = maskPath.CGPath;
        borderLayer.fillColor = [UIColor clearColor].CGColor;
        borderLayer.strokeColor = _borderColor.CGColor;
        borderLayer.lineWidth = 2;
        borderLayer.frame = _chatBackView.bounds;
        [borderLayer setName:@"lit"];
        [_chatBackView.layer addSublayer:borderLayer];
    }
    

    相关文章

      网友评论

          本文标题:IOS 给cell 中的view设置部分圆角

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