UIBezier类可以绘制不同类型的图形,它是Core Graphics框架的封装,可以绘制不同的图形,线,多边形,矩形,圆,椭圆,弧形,二次元贝塞尔曲线,三次贝塞尔曲线dengdeng
它的一个重要方法
1、-(void)stroked //空心的线的图形
2、-(void)fill //实心的图形
它的使用方法:
1、创建一个UIBezierPath对象
2、使用方法moveToPoint:去设置起始坐标
3、添加活着Curve去定义一个或者多个subpaths
4、通过调用UIBezier的属性改变形状
代码如下 简陋代码
//
// BezierView.m
// BezierPathDemo
//
// Created by xiaoqiang on 15/9/20.
// Copyright © 2015年 xiaoqiang. All rights reserved.
//
#import "BezierView.h"
@implementation BezierView
//重写
-(void)drawRect:(CGRect)rect{
UIColor *color = [UIColor redColor];
[color set];//设置颜色
UIBezierPath *path = [[UIBezierPath alloc] init];
[path setLineWidth: 5];//设置比的宽度
[path setLineCapStyle:kCGLineCapRound];
[path setLineJoinStyle:kCGLineJoinRound];
//线
[path moveToPoint:CGPointMake(150, 50)];
[path addLineToPoint:CGPointMake(100, 100)];
[path addLineToPoint:CGPointMake(100, 200)];
[path addLineToPoint:CGPointMake(200, 200)];
[path addLineToPoint:CGPointMake(200, 100)];
[path closePath];//不加这句 它不会自动首尾链接
[path stroke];
//创建一个矩形
UIBezierPath *path1 = [UIBezierPath bezierPathWithRect:CGRectMake(50, 220, 50, 100)];
path1.lineWidth = 5;
path1.lineCapStyle = kCGLineCapRound;
path1.lineCapStyle = kCGLineJoinRound;
[path1 stroke];
//创建一个圆
UIBezierPath *path2 = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(200, 220, 100, 100)];
[path2 stroke];
//椭圆
UIBezierPath *path3 = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 350, 100, 50)];
[path3 stroke];
//弧形
UIBezierPath *path4 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(200, 350) radius:50 startAngle:0 endAngle:M_PI * 2 clockwise:YES];
[path4 stroke];
//二次贝塞尔曲线
UIBezierPath *path5 =[UIBezierPath bezierPath];
[path5 moveToPoint:CGPointMake(200, 450)];
[path5 addQuadCurveToPoint:CGPointMake(100, 550) controlPoint:CGPointMake(300, 550)];
[path5 stroke];
//三次贝塞尔曲线
UIBezierPath *path6 =[UIBezierPath bezierPath];
[path6 moveToPoint:CGPointMake(200, 550)];
[path6 addCurveToPoint:CGPointMake(300, 600) controlPoint1:CGPointMake(500, 700) controlPoint2:CGPointMake(100, 750)];
[path6 stroke];
}
-(id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor whiteColor];
}
return self;
}
@end