BezierPath绘制
来源:互联网 发布:2017淘宝扣分清零规则 编辑:程序博客网 时间:2024/05/19 09:16
自定义曲线#import <UIKit/UIKit.h>typedef enum{ BrokenLineType,////折线类型 RectangleType,////矩形(正方形) RoundType,////圆形(椭圆)、圆环 ArcType,///弧线(扇形) CurveType,////曲线}PathType;@interface NewView : UIView@end#import "NewView.h"@interface NewView()@property (nonatomic, assign)PathType pathType;@end@implementation NewView/* 自定义视图的时候可以通过drawRect方法绘制,在需要更新绘制的时候可以通过[self setNeedsDisplay];来重新绘制,最好在自定义视图类内部完成, */- (void)setBezierType:(PathType)pathType{ _pathType = pathType; [self setNeedsDisplay];}-(void)drawRect:(CGRect)rect{ /* ///把自定义视图上面的绘制线全部填充覆盖掉 CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, self.backgroundColor.CGColor); CGContextFillRect(context, CGRectMake(0, 0, 0, 0));////作用范围 */ [super drawRect:rect]; UIColor *redColor = [UIColor redColor]; [redColor set]; switch (_pathType) { case BrokenLineType:{///绘制折线 CGPoint startPoint = CGPointMake(33, 33); CGPoint stopPoint = CGPointMake(57, 68); CGPoint nextPoint = CGPointMake(80, 40); UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:startPoint]; [path addLineToPoint:stopPoint]; [path addLineToPoint:nextPoint]; path.lineCapStyle = kCGLineCapRound; //线条拐角 path.lineJoinStyle = kCGLineCapRound; //终点处理 path.lineWidth = 1;////设置线宽 // [path stroke];////根据坐标点连线 [path closePath]; [path fill];////这个是直接填充 和stroke相对应 break; } case RectangleType:{////绘制矩形 UIBezierPath *juXing = [UIBezierPath bezierPathWithRect:CGRectMake(50, 80, 30, 40)]; [redColor set]; juXing.lineWidth = 0.5; juXing.lineCapStyle = kCGLineCapRound; //线条拐角 juXing.lineJoinStyle = kCGLineCapRound; //终点处理 [juXing stroke];////需要连线 break; } case RoundType:{////绘制圆或者椭圆 /* bezierPathWithOvalInRect:<#(CGRect)#> 此参数传矩形方框绘制的就是矩形方框的内切椭圆------传入正方形绘制的就是内切圆 */ UIBezierPath *yuan = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 80, 30, 40)]; [redColor set]; yuan.lineWidth = 0.5; [yuan stroke];////需要连线 break; } case ArcType:{///绘制弧线////或者扇形 CGPoint centerPoint = CGPointMake(150, 150); UIBezierPath* huXian = [UIBezierPath bezierPathWithArcCenter:centerPoint///中心点 radius:75///半径 startAngle:0///开始角度 endAngle:M_PI*2/3.0////结束角度 clockwise:YES]; huXian.lineWidth = 5.0; huXian.lineCapStyle = kCGLineCapRound; //线条拐角 huXian.lineJoinStyle = kCGLineCapRound; //终点处理 [huXian addLineToPoint:centerPoint]; [huXian closePath]; [huXian fill]; // [huXian stroke]; break; } case CurveType:{////绘制二/三次贝塞尔曲线 UIBezierPath *erCiBe = [UIBezierPath bezierPath]; erCiBe.lineWidth = 1.0; erCiBe.lineCapStyle = kCGLineCapRound; //线条拐角 erCiBe.lineJoinStyle = kCGLineCapRound; //终点处理 CGPoint startPoint = CGPointMake(40, 80); CGPoint stopPoint = CGPointMake(160, 120); CGPoint controlPoint = CGPointMake(70, 50); [erCiBe moveToPoint:startPoint]; ////绘制二次 [erCiBe addQuadCurveToPoint:stopPoint controlPoint:controlPoint]; CGPoint controlPoint0 = CGPointMake(80, 90); ///绘制三次 // [erCiBe addCurveToPoint:stopPoint controlPoint1:controlPoint controlPoint2:controlPoint0]; [erCiBe stroke]; break; } default: break; }}@end
0 0
- BezierPath绘制
- BezierPath
- BezierPath 使用(1)-- 绘制圆角
- iOS BezierPath 贝塞尔曲线的绘制
- bezierPath 不显示
- iOS BezierPath 详解
- BezierPath精讲
- bezierpath 常用方法备注一
- IOS BezierPath 贝塞尔曲线画图详解
- 绘制
- 绘制一棵树
- 绘制直方图
- 绘制平行线
- 绘制曲线
- 绘制边框
- 绘制图形
- 位图绘制
- 绘制文字
- Animation.setFillAfter and Animation.setFillBefore的作用
- Two Sum
- js 时间设置
- java代码运行.bat或.exe文件
- [转]Android底部弹出的View,可自定义布局
- BezierPath绘制
- vc6.0 和2008 添加一个类无法再classview中显示
- SAP HANA快捷键2(部分)
- js身份证号正则表达式验证
- Solr调优参考
- linux spec文档解析
- 调试的错误就是编程给你最好的东西,因为在每个错误上面都标志着前进的一步
- 极光推送技术原理:移动无线网络长连接
- 我的测试