UIBezierPath 画圆角直线 2023-02-08

2023-02-07  本文已影响0人  iOS打怪升级

为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
上一篇 下一篇

猜你喜欢

热点阅读