为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;
}
}
![](https://img.haomeiwen.com/i589368/dda35599512d7381.png)
image.png
贝塞尔相关内容,注意绘制起点,是否顺时针方向
![](https://img.haomeiwen.com/i589368/a098973dbba81d54.png)
image.png
网友评论