UIBezierPath类可以创建基于矢量的路径,可以定义简单的形状,如椭圆或者矩形,或者有多个直线和曲线段组成的形状。
一、UIBezierPath使用:
1、创建path;
2、添加路径到path;
3、将path绘制出来;
1 //创建path 2 path = [UIBezierPath bezierPath]; 3 //添加路径 4 [path moveToPoint:(CGPoint){ 10,50}]; 5 [path addLineToPoint:(CGPoint){ 100,50}]; 6 //将path绘制出来 7 [path stroke]; 8
二、实例
1、绘制多边形
注意:这个类要继承自UIView。
1 #import "Draw.h" 2 3 @interface Draw (){ 4 5 UIBezierPath *path; 6 7 } 8 9 @end 10 11 - (void)drawRect:(CGRect)rect { 12 13 //线条颜色 14 UIColor *color = [UIColor orangeColor]; 15 [color set]; 16 17 //创建path 18 path = [UIBezierPath bezierPath]; 19 //设置线宽 20 path.lineWidth = 3; 21