美文网首页
UIBezierPath 画圆角直线 2023-02-08

UIBezierPath 画圆角直线 2023-02-08

作者: iOS打怪升级 | 来源:发表于2023-02-07 14:12 被阅读0次

为tableview cell 绘制圆角直线

 - (UIBezierPath *)createPath
{
    UIBezierPath *path = [UIBezierPath bezierPath];
    NSInteger height = self.bounds.size.height;
    NSInteger width = self.bounds.size.width;
    NSInteger radius = 8;
    NSInteger left = 15;
    [path addArcWithCenter:CGPointMake(left + radius, height-radius) radius:radius startAngle:M_PI endAngle:M_PI_2 clockwise:NO];
    [path addLineToPoint:CGPointMake(width - radius*2, height)];
    [path addArcWithCenter:CGPointMake(width -radius -left, height - radius)radius:radius startAngle:M_PI_2 endAngle:0 clockwise:NO];
    [path stroke];
    return path;
}

用layer 显示绘制:
        CAShapeLayer *lineLayer = [CAShapeLayer new];
        lineLayer.lineWidth = 1;
        lineLayer.strokeColor = HQGoodsDetail_HexRGB(0xECECEC).CGColor;
        lineLayer.fillColor = UIColor.clearColor.CGColor;
        UIBezierPath *path = [self createPath];
        lineLayer.path = path.CGPath;
       
        _bottomCornerLine = lineLayer;
        [self.contentView.layer addSublayer:_bottomCornerLine];
#如果cell 高度不固定,可以考虑放到
- (void)layoutSubviews
{
    [super layoutSubviews];
    if (!self.bottomCornerLine.hidden) {
        self.bottomCornerLine.path = [self createPath].CGPath;
    }
}

image.png
贝塞尔相关内容,注意绘制起点,是否顺时针方向
image.png

相关文章

网友评论

      本文标题:UIBezierPath 画圆角直线 2023-02-08

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