1.空心圆圈
// 创建
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(20, 20, 200, 200) cornerRadius:100];
// 设置属性
path.lineWidth = 5;
path.lineCapStyle = kCGLineCapRound;
path.lineJoinStyle = kCGLineJoinRound;
[[UIColor redColor] set];
// 绘制
[path stroke];2.实心圆
// 创建
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(20, 20, 200, 200) cornerRadius:100];
// 设置属性
path.lineWidth = 5;
path.lineCapStyle = kCGLineCapRound;
path.lineJoinStyle = kCGLineJoinRound;
[[UIColor redColor] set];
// 填充(必须是一个完整的封闭路径)
[path fill];3.圆弧
/*
center:圆心
startAngle: 弧度
clockwise:YES顺时针/NO逆时针
*/
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) radius:100 startAngle:0 endAngle:-M_PI_2 clockwise:NO];
path.lineWidth = 5;
[[UIColor orangeColor] set];
[path stroke];4.扇形
// 扇形
CGPoint center = CGPointMake(150, 150);
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:100 startAngle:0 endAngle:-M_PI_2 clockwise:NO];
// 添加一根线到圆心
[path addLineToPoint:center];
// 关闭路径(从路径的终点到起点)
[path closePath];
path.lineWidth = 5;
[[UIColor redColor] set];
[path fill];
本文介绍了如何使用UIBezierPath在iOS应用中绘制各种圆形UI元素,包括空心圆圈、实心圆、圆弧及扇形。通过调整路径属性如线条宽度、线帽样式等,并利用填充和描边的方法实现不同视觉效果。

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



