March.5th

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:传入的矩形是一个正方形,那么就会得到一个圆,不是正方形是就是椭圆

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1.使用UIBezierPath画图步骤 创建一个UIBezierPath对象 调用-moveToPoint:设置...
    翘楚iOS9阅读 4,017评论 1 2
  • Quartz2D以及drawRect的重绘机制字数1487 阅读21 评论1 喜欢1一、什么是Quartz2D Q...
    PurpleWind阅读 4,274评论 0 3
  • UIBezierPath详解 我在写本篇文章之前,也没有系统学习过贝塞尔曲线,只是曾经某一次的需求需要使用到,才临...
    白水灬煮一切阅读 4,952评论 0 4
  • 基础知识 使用UIBezierPath可以创建基于矢量的路径,此类是Core Graphics框架关于路径的封装。...
    十里桃花不及你阅读 4,361评论 0 5
  • 家是什么? 家是什么?是一束温暖的阳光,可以融化掉心上的冰雪寒霜;是一盏明灯,可以照亮夜行人晚归的路程;是一个温馨...
    呜哩哇啦叭叭叭阅读 2,958评论 0 0

友情链接更多精彩内容