关于UIBezierPath的使用
2015-09-28 14:35
399 查看
使用UIBezierPath类可以创建基于矢量的路径。此类是Core
Graphics框架关于path的一个封装。使用此类可以定义简单的形状,如椭圆或者矩形,或者有多个直线和曲线段组成的形状。
例:
先看效果图:
UIColor *color = [UIColor
redColor] ;
[color set];
//设置颜色
//方形
UIBezierPath* square = [UIBezierPath
bezierPathWithRect:CGRectMake(20,
20, 50,
50)];
//图形的宽度
square.lineWidth =
1.0;
//边框
[square stroke];
//椭圆
UIBezierPath* ellipse = [UIBezierPath
bezierPathWithOvalInRect:CGRectMake(20,
100, 150,
50)];
[ellipse fill];
//圆形
//参数:
圆心坐标 半径
开始角度 结束角度
方向是:顺、逆时针
//圆 = 2pi = 360° M_PI_4 =
圆的/8 = 45°
//这里是顺时针算角度
UIBezierPath* circular = [UIBezierPath
bezierPathWithArcCenter:CGPointMake(25,
180) radius:25
startAngle:0
endAngle:M_PI_4
clockwise:NO];
[circular stroke];
/*----绘制二次贝塞尔曲线----*/
UIBezierPath* twoCurve = [UIBezierPath
bezierPath];
//启示位置
[twoCurve moveToPoint:CGPointMake(20,
220)];
//终止位置
曲线方形位置
[twoCurve addQuadCurveToPoint:CGPointMake(20,
260) controlPoint:CGPointMake(120,
260)];
[twoCurve stroke];
/*----绘制三次贝塞尔曲线----*/
UIBezierPath* thridCurve = [UIBezierPath
bezierPath];
//启示位置
[thridCurve moveToPoint:CGPointMake(10,
320)];
//终止位置
第一曲线方形位置 第二曲线方形位置
[thridCurve addCurveToPoint:CGPointMake(310,
320) controlPoint1:CGPointMake(110,220)
controlPoint2:CGPointMake(210,
420)];
[thridCurve stroke];
/*----自定义绘图----*/ 五边形
UIBezierPath* drawPath = [UIBezierPath
bezierPath];
[drawPath moveToPoint:CGPointMake(100.0,
400.0)];
[drawPath addLineToPoint:CGPointMake(200.0,
440.0)];
[drawPath
bdb6
addLineToPoint:CGPointMake(160,
540)];
[drawPath addLineToPoint:CGPointMake(40.0,
540)];
[drawPath addLineToPoint:CGPointMake(0.0,
440.0)];
//设置颜色
[[UIColor
blackColor] setStroke];
//结束绘图
[drawPath closePath];
[drawPath stroke];
方法 原理图解:
- (void)addQuadCurveToPoint:(CGPoint)endPoint controlPoint:(CGPoint)controlPoint;
- (void)addCurveToPoint:(CGPoint)endPoint controlPoint1:(CGPoint)controlPoint1 controlPoint2:(CGPoint)controlPoint2;
- (void)addArcWithCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle
endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise NS_AVAILABLE_IOS(4_0);
Graphics框架关于path的一个封装。使用此类可以定义简单的形状,如椭圆或者矩形,或者有多个直线和曲线段组成的形状。
例:
先看效果图:
UIColor *color = [UIColor
redColor] ;
[color set];
//设置颜色
//方形
UIBezierPath* square = [UIBezierPath
bezierPathWithRect:CGRectMake(20,
20, 50,
50)];
//图形的宽度
square.lineWidth =
1.0;
//边框
[square stroke];
//椭圆
UIBezierPath* ellipse = [UIBezierPath
bezierPathWithOvalInRect:CGRectMake(20,
100, 150,
50)];
[ellipse fill];
//圆形
//参数:
圆心坐标 半径
开始角度 结束角度
方向是:顺、逆时针
//圆 = 2pi = 360° M_PI_4 =
圆的/8 = 45°
//这里是顺时针算角度
UIBezierPath* circular = [UIBezierPath
bezierPathWithArcCenter:CGPointMake(25,
180) radius:25
startAngle:0
endAngle:M_PI_4
clockwise:NO];
[circular stroke];
/*----绘制二次贝塞尔曲线----*/
UIBezierPath* twoCurve = [UIBezierPath
bezierPath];
//启示位置
[twoCurve moveToPoint:CGPointMake(20,
220)];
//终止位置
曲线方形位置
[twoCurve addQuadCurveToPoint:CGPointMake(20,
260) controlPoint:CGPointMake(120,
260)];
[twoCurve stroke];
/*----绘制三次贝塞尔曲线----*/
UIBezierPath* thridCurve = [UIBezierPath
bezierPath];
//启示位置
[thridCurve moveToPoint:CGPointMake(10,
320)];
//终止位置
第一曲线方形位置 第二曲线方形位置
[thridCurve addCurveToPoint:CGPointMake(310,
320) controlPoint1:CGPointMake(110,220)
controlPoint2:CGPointMake(210,
420)];
[thridCurve stroke];
/*----自定义绘图----*/ 五边形
UIBezierPath* drawPath = [UIBezierPath
bezierPath];
[drawPath moveToPoint:CGPointMake(100.0,
400.0)];
[drawPath addLineToPoint:CGPointMake(200.0,
440.0)];
[drawPath
bdb6
addLineToPoint:CGPointMake(160,
540)];
[drawPath addLineToPoint:CGPointMake(40.0,
540)];
[drawPath addLineToPoint:CGPointMake(0.0,
440.0)];
//设置颜色
[[UIColor
blackColor] setStroke];
//结束绘图
[drawPath closePath];
[drawPath stroke];
方法 原理图解:
- (void)addQuadCurveToPoint:(CGPoint)endPoint controlPoint:(CGPoint)controlPoint;
- (void)addCurveToPoint:(CGPoint)endPoint controlPoint1:(CGPoint)controlPoint1 controlPoint2:(CGPoint)controlPoint2;
- (void)addArcWithCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle
endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise NS_AVAILABLE_IOS(4_0);
相关文章推荐
- EasyUI 格式化列
- 在非Activity(非主线程)中更新UI的办法:(一)Handler+Thread+Activity静态成员变量
- Xcode 7 UI 测试初窥
- break ,continue ,return的区别
- SoapUI中XML解析
- Json转换利器Gson-Gson注解和GsonBuilder
- Android UI - 实现广告Banner轮播效果
- Groovy Script in SoapUI REST Testing
- UI Overview
- UML之时序图(Sequence Diagram)
- 进度条 UIProgressView
- iOS开发UI篇—iOS开发中三种简单的动画设置
- 最简单的推送--uexGetui
- iOS UI进阶-1.1 Quartz2D 图片水印/裁剪/截图
- IDEA Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executin
- hashtable ,hashmap的containsValue与containsKey
- ERROR! The server quit without updating PID file!!!(已解决!!!)
- iOS 【UIKit-performSelector】
- UIButton和UILabel设置圆角
- 为安卓应用申请更大的内存 largeHeap="true"