UIBezierPath 赛贝尔曲线
来源:互联网 发布:虫族建筑知乎 编辑:程序博客网 时间:2024/04/29 14:25
首先我们创建的UIView的类,然后重写drawRect方法。在里面进行绘制赛贝尔曲线。
我们经常绘制的图案包括矩形、椭圆、N边形、(二次、三次)赛贝尔曲线、弧线、其余的图形绘制在以后将会讲到
在绘图的时候,有两个属性:
lineCapStyle 和 lineJoinStyle
/* lineCapStyle :线条拐角帽的样式 kCGLineCapButt, 默认 kCGLineCapRound, 轻微圆角 kCGLineCapSquare 正方形 */ path.lineCapStyle = kCGLineCapSquare; /* lineJoinStyle :两条线连接点的样式 kCGLineJoinMiter, 斜接 kCGLineJoinRound, 圆滑衔接 kCGLineJoinBevel 斜角连接 */ path.lineJoinStyle = kCGLineJoinMiter;
1、画矩形。
在矩形绘制中,有三种类方法。
- (void)drawRectangle{ CGRect newRect = CGRectMake(20, 20, 220, 200); //矩形// UIBezierPath *path = [UIBezierPath bezierPathWithRect:newRect]; //带圆角的矩形// UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:newRect cornerRadius:8.0f]; //某个角设置为圆角 //cornerRadii: size 设置为正方形,即使不是正方形,也会按照正方形切圆角 UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:newRect byRoundingCorners:UIRectCornerTopLeft cornerRadii:CGSizeMake(80, 10)]; path.lineWidth = 11.0f; //设置填充颜色 UIColor *fillColor = [UIColor greenColor]; [fillColor set]; [path fill]; //设置线条颜色 UIColor *strokeColor = [UIColor blueColor]; [strokeColor set]; [path stroke]; }
2、绘制N边形
在此以三角形为例子,当然你也可以addLineToPoint来添加你想要添加的点
/** *画三角形 */- (void)drawTriangle{ UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:CGPointMake(20, 20)]; [path addLineToPoint:CGPointMake(220, 20)]; [path addLineToPoint:CGPointMake(80, 140)]; [path closePath]; //线的粗细 path.lineWidth = 11.0f; //填充色 [[UIColor greenColor] set]; [path fill]; //边线色 [[UIColor redColor] set]; [path stroke]; }
我们只要宽高大小相同,那么就会变成圆了。
/** * 画椭圆 */- (void)drawCircle{ CGRect newRect = CGRectMake(20, 20, 220, 120); UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:newRect]; [[UIColor greenColor] set]; [path fill]; [path stroke]; }
4、绘制弧形
(图片来自于:http://www.jianshu.com/p/734b34e82135)
在这我们可以看到,float类型想要的内容是弧度度数。
/** * 画弧 */- (void)drawRAD{ CGPoint start = CGPointMake(150, 150); CGFloat endFloat = M_PI/180*270; //要的是弧度。 //clockwise(顺时针) :YES 是顺时针,NO是逆时针 UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:start radius:100 startAngle:0 endAngle:endFloat clockwise:YES]; path.lineCapStyle = kCGLineCapRound; path.lineJoinStyle = kCGLineJoinRound; path.lineWidth = 10.0; [[UIColor redColor] set]; [path stroke]; }
5、赛贝尔曲线。
/** * 二次赛贝尔曲线 */- (void)secondBezier{ UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:CGPointMake(20, 230)]; [path addQuadCurveToPoint:CGPointMake(220, 210) controlPoint:CGPointMake(50, 80)]; path.lineCapStyle = kCGLineCapRound; path.lineJoinStyle = kCGLineJoinRound; path.lineWidth = 7.0; [[UIColor redColor] set]; [path stroke]; }
/** * 三次赛贝尔曲线 */- (void)thirdBezier{ UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:CGPointMake(20, 150)]; [path addCurveToPoint:CGPointMake(280,130) controlPoint1:CGPointMake(50, 0) controlPoint2:CGPointMake(120, 250)]; path.lineCapStyle = kCGLineCapRound; path.lineJoinStyle = kCGLineJoinBevel; path.lineWidth = 7.0; [[UIColor redColor] set]; [path stroke]; }
0 0
- UIBezierPath 赛贝尔曲线
- UIBezierPath 贝尔曲线
- 赛贝尔曲线
- 贝尔曲线
- NSBezierPath 赛贝尔曲线画聊天泡泡
- NSBezierPath 赛贝尔曲线画聊天泡泡
- NSBezierPath 赛贝尔曲线画聊天泡泡
- UIBezierPath贝塞尔曲线
- 贝塞尔曲线UIBezierPath 详解
- 贝塞尔曲线UIBezierPath
- UIBezierPath - 贝塞尔曲线
- iOS UIBezierPath--贝塞尔曲线
- 贝塞尔曲线 UIBezierPath
- 贝塞尔曲线 UIBezierPath
- CGContextRef + UIBezierPath贝塞尔曲线
- iOS贝塞尔曲线UIBezierPath
- iOS开发 贝塞尔曲线UIBezierPath
- iOS开发 贝塞尔曲线UIBezierPath
- 快速求朋友数(暂时还没有看懂)当模板用吧
- 字符串最后一个单词的长度
- Git撤销Commit操作
- 一个测试博客
- 1016 水仙花数 V2
- UIBezierPath 赛贝尔曲线
- Android屏幕适配方案
- HIVE和HBASE区别
- 软件项目免坑指南
- chrome gn,gyp使用
- array_map(myfunction,array1,array2,array3...) array_walk(array,myfunction,userdata...)
- JS实现鼠标点击展开或隐藏表格行的方法
- IBM 专业的统计分析平台SPSS Statistics 24.0新功能介绍
- 浅谈BigDecimal