跟绘制火柴人方法类似,但这里我们不需要一条条的线来绘制,有更快捷的方法:
//指定矩形大小
CGRect rect=CGRectMake(50, 300, 100, 100);
//设置圆角半径
CGSize size=CGSizeMake(20, 20);
//拿出需要设置改动的角
UIRectCorner corners=UIRectCornerTopRight | UIRectCornerBottomRight |UIRectCornerBottomLeft;
//这里是上面两步的综合,具体的操作执行
UIBezierPath *rectPath=[UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corners cornerRadii:size];
//图形子类来渲染
CAShapeLayer *rectLayer=[CAShapeLayer layer];
//线条颜色
rectLayer.strokeColor=[UIColor greenColor].CGColor;
//填充颜色
rectLayer.fillColor=[UIColor orangeColor].CGColor;
//线条宽度
rectLayer.lineWidth=5;
//起始结束点的样式
rectLayer.lineJoin=kCALineJoinRound;
//线条拐角的样式
rectLayer.lineCap=kCALineCapRound;
rectLayer.path=rectPath.CGPath;
[self.view.layer addSublayer:rectLayer];
代码参见火柴人代码下面的代码:https://github.com/codeliu6572/FirePeople
本文介绍了一种使用UIBezierPath快速绘制带有特定圆角的矩形的方法,并详细展示了如何通过代码设置圆角半径及线条样式。

被折叠的 条评论
为什么被折叠?



