March.5th

2016-05-21  本文已影响33人  kingandyoga

CGGeometry.h ( 几何类 )
一 几个常用结构体

struct CGPoint {

CGFloat x;

CGFloat y;

}; 定义一个点,设置x坐标和y坐标

struct CGSize {

CGFloat width;

CGFloat height;

}; 定义一个尺寸,设置宽度和高度

struct CGVector {

CGFloat dx;

CGFloat dy;

}; 定义一个二维矢量

struct CGRect {

CGPoint origin;

CGSize size;

}; 定义一个矩形

UIImage

todo

UIBezierPath:http://www.henishuo.com/uibezierpath-draw/
一.画图步骤
1.创建一个UIBezierPath对象
2.调用-moveToPoint:设置初始线段的起点
3.添加线或者曲线去定义一个或者多个子路径
4.改变对象跟绘图相关的属性:(画笔的颜色 样式等等)

二.创建方法
****+ (****instancetype****)****bezierPath;****
最常用的创建方法,可以画任意图形

****+ (****instancetype****)****bezierPathWithRect****:****(****CGRect****)****rect;****
画一个矩形曲线

****+ (****instancetype****)****bezierPathWithOvalInRect****:****(****CGRect****)****rect;****
通常用来画圆和椭圆

****+ (****instancetype****)****bezierPathWithRoundedRect****:****(****CGRect****)rect****
**** cornerRadius**:****(****CGFloat****)****cornerRadius****;******
用来画矩形,可以画圆角矩形,第一个参数是矩形大小位置,第二个是圆角大小


****+ (****instancetype****)****bezierPathWithRoundedRect****:****(****CGRect****)rect****
**** byRoundingCorners:****(****UIRectCorner****)****corners******
**** cornerRadii
:****(****CGSize****)****cornerRadii****;******
方法类似上面的,可以指定哪一个角是圆角



****+ (****instancetype****)****bezierPathWithArcCenter****:****(****CGPoint****)center****
**** radius:****(****CGFloat****)****radius******
**** startAngle
:****(****CGFloat****)****startAngle******
**** endAngle:****(****CGFloat****)****endAngle******
**** clockwise
:****(****BOOL****)****clockwise****;******
用来画圆弧


****+ **(****instancetype****)****bezierPathWithCGPath****:****(****CGPathRef****)****CGPath****;******


三.效果(图可以参见上面的网址)
1.画三角形
UIBezierPath *path = [UIBezierPath bezierPath];
//设置路径的起点

[path moveToPoint:CGPointMake(20, 20)];
//移动路径到直线的另一点

[path addLineToPoint:CGPointMake(self.frame.size.width - 40, 20)];
[path addLineToPoint:CGPointMake(self.frame.size.width / 2, self.frame.size.height - 20)];

// 最后的闭合线是可以通过调用closePath方法来自动生成的,也可以调用-addLineToPoint:方法来添加
// [path addLineToPoint:CGPointMake(20, 20)];

[path closePath];

// 设置线宽
path.lineWidth = 1.5;

// 设置填充颜色
UIColor *fillColor = [UIColor greenColor];
//启动一下颜色

[fillColor set];
//给路线填充颜色

[path fill];

// 设置画笔颜色
UIColor *strokeColor = [UIColor blueColor];
[strokeColor set];

// 根据我们设置的各个点连线
[path stroke];

2.画矩形
1⃣普通矩形
UIBezierPath *path = [UIBezierPath bezierPathWithRect:
CGRectMake(20, 20, self.frame.size.width - 40, self.frame.size.height - 40)];

2⃣圆角矩形
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:
CGRectMake(20, 20, self.frame.size.width - 40, self.frame.size.height - 40)
cornerRadius:10];
3⃣特定角是圆角
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:
CGRectMake(20, 20, self.frame.size.width - 40, self.frame.size.height - 40)
byRoundingCorners:UIRectCornerTopRight cornerRadii:CGSizeMake(20, 20)];

4⃣画圆跟椭圆
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:
CGRectMake(20, 20, self.frame.size.width - 40, self.frame.size.width - 40)];
ps:传入的矩形是一个正方形,那么就会得到一个圆,不是正方形是就是椭圆

上一篇下一篇

猜你喜欢

热点阅读