UIBezierPath
- (void)drawRect:(CGRect)rect {
//1.創(chuàng)建貝塞爾路徑的實例
UIBezierPath *path = [UIBezierPath bezierPath];
//2.勾勒圖形
[path moveToPoint:CGPointMake(40, 40)];
[path addLineToPoint:CGPointMake(140, 40)];
[path addLineToPoint:CGPointMake(140, 140)];
[path addLineToPoint:CGPointMake(40, 140)];
// [path addLineToPoint:CGPointMake(40, 40)];
[path closePath];
[path moveToPoint:CGPointMake(40, 200)];
[path addLineToPoint:CGPointMake(140, 200)];
[path addLineToPoint:CGPointMake(140, 300)];
[path addLineToPoint:CGPointMake(40, 300)];
[path closePath];
//設置描邊線的寬度
path.lineWidth = 10;
//焦點的樣式
// kCGLineJoinMiter, //尖的
// kCGLineJoinRound, //圓的
// kCGLineJoinBevel //斜的 角被砍掉
path.lineJoinStyle = kCGLineJoinBevel;
//線兩端的樣式
// kCGLineCapButt, //方的
// kCGLineCapRound, //圓的 多出一塊
// kCGLineCapSquare //方的 多出一塊
path.lineCapStyle = kCGLineCapSquare;
//設置 描邊顏色
[[UIColor redColor] setStroke];
//設置 填充顏色
[[UIColor greenColor] setFill];
//描邊
[path stroke];
//填充
[path fill];
}
- (void)drawRect:(CGRect)rect {
UIBezierPath *path = [UIBezierPath bezierPath];
//clockwise 為YES順時針 為NO逆時針
[path addArcWithCenter:CGPointMake(100, 100) radius:80 startAngle:M_PI_2 * 3 endAngle:0 clockwise:YES];
[path addLineToPoint:CGPointMake(100, 100)];
[path closePath];
//移動畫筆
// [path moveToPoint:CGPointMake(100, 180)];
// [path addArcWithCenter:CGPointMake(100, 100) radius:80 startAngle:M_PI_2 endAngle:M_PI clockwise:YES];
// [path addLineToPoint:CGPointMake(100, 100)];
// [path closePath];
path.lineWidth = 8;
[[UIColor redColor] setStroke];
[path stroke];
[[UIColor greenColor] setFill];
[path fill];
}
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(140, 40)];
//添加兩個控制點 和 終點
[path addCurveToPoint:CGPointMake(40, 180) controlPoint1:CGPointMake(40, 40) controlPoint2:CGPointMake(140, 180)];
[path addCurveToPoint:CGPointMake(140, 320) controlPoint1:CGPointMake(140, 180) controlPoint2:CGPointMake(40, 320)];
[[UIColor redColor]setStroke];
[path stroke];
UIBezierPath *rectPath = [UIBezierPath bezierPathWithRect:CGRectMake(50, 50, 200, 80)];
rectPath.lineWidth = 5;
[[UIColor greenColor] setStroke];
[rectPath stroke];
UIBezierPath *roundedRect = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(50, 150, 200, 80) cornerRadius:20];
[roundedRect stroke];
UIBezierPath *oval = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 250, 200, 80)];
[oval stroke];