内接矩形,bezierPathWithRect:
[[UIColor redColor]setStroke];
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 150, 150)];
path.lineWidth = 5;
path.lineCapStyle = kCGLineCapRound;
[path stroke];
内接圆角矩形(可画圆)bezierPathWithRoundedRect:cornerRadius:
// 正方形极限是内接圆,长方形极限是内接椭圆
[[UIColor greenColor]setFill];
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 150, 150) cornerRadius:75];
path.lineWidth = 1;
[path fill];
内接圆角+锐角矩形 bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:
// 设置线的填充色
[[UIColor greenColor] setStroke];
// 新建一个bezier对象,此对象用于绘制一个部分圆角的矩形,左上、右下
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(10, 10, 280, 280)
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomRight
cornerRadii:CGSizeMake(10, 10)];
// 设置线宽度
bezierPath.lineWidth = 10;
// 开始绘制
[bezierPath stroke];
内接圆 bezierPathWithOvalInRect:
内接圆弧 bezierPathWithArcCenter:radius:startAngle:endAngle:clockwise:
- radius圆半径
- startAngle = 0 从圆心直角坐标系(radius,0)坐标开始
- clockwise = YES 顺时针绘制
- endAngle M_PI = 180度 , M_PI_2 = 90度,角度为顺时针角度,逆时针绘制时,绘制的是逆时针部分,例如M_PI_2绘制的就是逆时针的180 + 90度
CGRectInset
frame = (100,100,50,50)
x = 10;
y = 10;
result = CGRectInset(frame, x, y);
result = (100 - x, 100 - y,50 - x * 2, 50 - y * 2);
// 根据一个点和半径,创建这个圆的贝塞尔曲线
[UIBezierPath bezierPathWithOvalInRect:CGRectInset(point.frame, -radius, -radius)]