IOS BezierPath 贝塞尔曲线画图详解
来源:互联网 发布:沪深300指数基金 知乎 编辑:程序博客网 时间:2024/05/19 00:14
//UIColor *blueColor=[UIColor redColor];
// 画一个矩形
// UIBezierPath *pathRect=[UIBezierPath bezierPathWithRect:CGRectMake(20, 30, 200, 300)];
// UIColor *redColor=[UIColor redColor];
// [redColor set];
// [pathRect stroke];
// 在矩形里面画一个椭圆
// UIBezierPath *pathOval=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(20, 30, 200, 300)];
//
//
// [blueColor set];
// [pathOval stroke];
// 画一个圆角矩形
//UIBezierPath *pathRoundCorner=[UIBezierPath bezierPathWithRoundedRect:CGRectMake(20, 30, 200, 300) cornerRadius:5];
//
// [blueColor set];
// [pathRoundCorner stroke];
// 一个矩形选择其实的几个角是圆角的
// UIBezierPath *pathRoundCorners=[UIBezierPath bezierPathWithRoundedRect:CGRectMake(20, 30, 200, 300) byRoundingCorners:UIRectCornerTopLeft cornerRadii:CGSizeMake(10, 20)];
// [blueColor set];
// [pathRoundCorners stroke];
//画圆弧 0°是水平开始的
// UIBezierPath *pathArc=[UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 300) radius:100 startAngle:0 endAngle:M_PI*2 clockwise:YES];
//
// [blueColor set];
// [pathArc stroke];
// + (instancetype)bezierPathWithCGPath:(CGPathRef)CGPath; 这个功能没弄明白
//在不同的点之间连线
// UIBezierPath *path=[[UIBezierPath alloc]init];
// path.lineWidth=5;
// path.lineCapStyle=kCGLineCapButt;
// path.lineJoinStyle=kCGLineJoinBevel;
// [path moveToPoint:CGPointMake(20, 20)];
// [path addLineToPoint:CGPointMake(80, 80)];
// [path addLineToPoint:CGPointMake(20, 160)];
//
// [path closePath];
//
// [blueColor set];
// [path stroke];
// 三次贝塞尔曲线
// UIBezierPath *path=[[UIBezierPath alloc]init];
//
// path.lineWidth=5;
// path.lineJoinStyle=kCGLineJoinRound;
// path.lineCapStyle=kCGLineCapButt;
// [path moveToPoint:CGPointMake(20, 100)];
// [path addCurveToPoint:CGPointMake(240, 80) controlPoint1:CGPointMake(80, 40) controlPoint2:CGPointMake(160, 160)];
// [blueColor set];
// [path stroke];
//
// UIBezierPath *path=[[UIBezierPath alloc]init];
// [path moveToPoint:CGPointMake(20, 100)];
//
// [path addQuadCurveToPoint:CGPointMake(120, 120) controlPoint:CGPointMake(60, 40)];
//
// [blueColor set];
//
// [path stroke];
// UIBezierPath *path=[[UIBezierPath alloc]init];
// //path.flatness=80;
// [path addArcWithCenter:CGPointMake(100, 100) radius:80 startAngle:0 endAngle:M_PI*2 clockwise:YES];
// path.usesEvenOddFillRule=YES;
// [blueColor set];
//
// [path stroke];
//画虚线
UIBezierPath *path=[[UIBezierPathalloc]init];
[path moveToPoint:CGPointMake(20,100)];
[path addLineToPoint:CGPointMake(180,100)];
CGFloat lengths[] = {20,10,5};
//这是一个C 数组 意思就是先画20个像素长度的线段然后空10个像素 长度然后再画5个像素长度的线段反复循环下去。
[pathsetLineDash:lengthscount:3 phase:0];
//这里的phase是指位移 如果phase的参数是6 那么首先就是画(20-6)个像素长度的线段。
[[UIColorredColor]set];
[pathstroke];
以上贝塞尔曲线需要在view的函数-(void)drawRect:(CGRect)rect里面执行 但是也可以在view controller定义CAShapeLayer把画的曲线展现出来。
CAShapeLayer *layer = [[CAShapeLayer alloc]init];
layer.frame=CGRectMake(0, 0, 200, 400);
[self.view.layer addSublayer:layer];
UIBezierPath *bezierPath = [UIBezierPath bezierPath];
UIBezierPath *outerCircle = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(CGRectMake(0, 0, 150, 200), 4, 4)];
[outerCircle setLineWidth:2.0];
[bezierPath appendPath:outerCircle];
UIBezierPath *innerCircle = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(CGRectMake(50, 20, 150, 200), 20, 20)];
[innerCircle setLineWidth:2.0];
[bezierPath appendPath:innerCircle];
bezierPath.usesEvenOddFillRule = YES;
layer.path = bezierPath.CGPath;
layer.fillColor = [UIColor orangeColor].CGColor;
layer.strokeColor = [UIColor redColor].CGColor;
另外函数
- (void)fillWithBlendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha;
- (void)strokeWithBlendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha;
- IOS BezierPath 贝塞尔曲线画图详解
- iOS BezierPath 贝塞尔曲线的绘制
- iOS BezierPath 详解
- iOS 利用贝塞尔曲线画图
- BezierPath
- iOS画图详解
- android画图之贝塞尔曲线讲解
- ios画图API详解注释
- iOS 贝塞尔曲线和CAShapeLayer 结合使用的进度条详解
- iOS用CGContextRef画图(文字、圆、直线、弧线、矩形、扇形、椭圆、三角形、圆角矩形、贝塞尔曲线、图片)
- IOS贝塞尔曲线绘图
- iOS之贝塞尔曲线
- iOS开发 贝塞尔曲线
- iOS UIBezierPath--贝塞尔曲线
- iOS贝塞尔曲线UIBezierPath
- iOS 开发贝塞尔曲线
- iOS贝塞尔bezier曲线
- 画图(画曲线)
- java.lang.OutOfMemoryError: Java heap space 解决方法
- linux 信号 中断的系统调用
- php设计模式:值对象模式
- C#中的foreach语句与枚举器接口(IEnumerator)及其泛型 相关问题
- ZOJ 1014 OPERAND
- IOS BezierPath 贝塞尔曲线画图详解
- 238,安装mysql出现Access denied for user 'root'@'localhost' (using password: YES)的问题
- ubuntu 的 document viewer evince 发生 Could not open X display 错误的处理
- Android 四大组件 —— 广播(广播机制解析)
- Interview Notes
- CAS单点登陆的原理
- poj2492 A Bug's Life(并查集)
- Hadoop—archive
- 反馈通道改善系统性能_20160130