//绘制矩形
- (void)drawSequl
{
UIColor * color =[UIColor redColor];
//设置画笔颜色
[color setFill];
UIRectFill(CGRectMake(10, 10, 100, 100));
}
//绘制自定义矩形
- (void)drawDiySqul
{
//设置线条颜色
UIColor * color =[UIColor colorWithRed:0 green:0 blue:0.7 alpha:1];
[color set];
UIBezierPath * path = [UIBezierPath bezierPathWithRect:CGRectMake(10, 10, 100, 100)];
path.lineWidth = 2;
path.lineCapStyle = kCGLineCapRound; //设置线条的拐角
path.lineJoinStyle = kCGLineJoinRound; //终点处理
[path stroke];
}
//画圆
- (void)drawCircle
{
[[UIColor redColor] set];
// UIBezierPath * path =[UIBezierPath bezierPathWithRoundedRect:CGRectMake(10, 10, 400, 400) cornerRadius:200];
//画椭圆只要把高或者宽 改一下即可
UIBezierPath * path =[UIBezierPath bezierPathWithOvalInRect:CGRectMake(10, 10, 200, 200)];
path.lineWidth =8;
[path stroke];
}
//多边形
- (void)drawDiyGraph
{
//设置画笔颜色
[[UIColor orangeColor] set];
UIBezierPath * path =[UIBezierPath bezierPath];
path.lineWidth = 4;
path.lineCapStyle = kCGLineCapRound;
path.lineJoinStyle = kCGLineJoinRound;
//设置起点
[path moveToPoint:CGPointMake(10, 10)];
//绘制线条
[path addLineToPoint:CGPointMake(60, 10)];
[path addLineToPoint:CGPointMake(60, 20)];
[path addLineToPoint:CGPointMake(50, 70)];
[path addLineToPoint:CGPointMake(30, 120)];
[path addLineToPoint:CGPointMake(20, 200)];
//最后一条线封闭图形
[path closePath];
//根据坐标点连线
[path stroke];
//填充
[path fill];
}
//绘制不规则图形
- (void)drawIrregularity
{
//设置画笔颜色
[[UIColor whiteColor] set];
/*第一个参数圆点
第二个参数 半径
第三个参数 初始角度 (弧度使用顺时针脚底,0弧度指向右边,pi/2指向下方,pi指向左边,-pi/2指向上方)
第四个参数 结束角度
*/
UIBezierPath * path =[UIBezierPath bezierPathWithArcCenter:CGPointMake(100, 100) radius:90 startAngle:0 endAngle:3.14/2*3 clockwise:YES];
path.lineWidth = 8;
[path stroke];
}
//绘制贝塞尔曲线
- (void)drawBersizer
{
//设置画笔颜色
[[UIColor whiteColor]set];
UIBezierPath * path = [UIBezierPath bezierPath];
path.lineWidth = 4;
[path moveToPoint:CGPointMake(10, 210)];
[path addQuadCurveToPoint:CGPointMake(310, 210) controlPoint:CGPointMake(100, 50)];
[path stroke];
}
//贝塞尔波浪线
- (void)drawBolang
{
//设置画笔颜色
[[UIColor whiteColor]set];
//
UIBezierPath * path = [UIBezierPath bezierPath];
path.lineWidth =6;
[path moveToPoint:CGPointMake(10, 310)];
[path addCurveToPoint:CGPointMake(370, 310) controlPoint1:CGPointMake(130, 210) controlPoint2:CGPointMake(250, 410)];
[path stroke];
}
//波浪 (多个拐弯)
- (void)drawLLLL
{
[[UIColor whiteColor]set];
UIBezierPath * path = [UIBezierPath bezierPath];
path.lineWidth =4;
path.lineCapStyle = kCGLineCapRound;
[path moveToPoint:CGPointMake(0, 200)];
[path addQuadCurveToPoint:CGPointMake(100, 200) controlPoint:CGPointMake(50, 100)];
[path addQuadCurveToPoint:CGPointMake(200, 200) controlPoint:CGPointMake(150, 300)];
[path addQuadCurveToPoint:CGPointMake(300, 200) controlPoint:CGPointMake(250, 100)];
[path stroke];
}
iOS BezierPath 贝塞尔曲线的绘制
最新推荐文章于 2021-05-12 17:15:46 发布