ios 绘制曲线走势图

- (void)drawLine{

//view是曲线的背景

viewUIView *view = [[UIView alloc]initWithFrame:CGRectMake(10,0,300,300)];

view.backgroundColor = [UIColor whiteColor];

[self.view addSubview:view];

//第一、UIBezierPath绘制线段

UIBezierPath *path = [UIBezierPath bezierPath];

//四个点

CGPoint point = CGPointMake(10,10);

CGPoint point1 = CGPointMake(200,100);

CGPoint point2 = CGPointMake(240,200);

CGPoint point3 = CGPointMake(290,200);

NSArray *arr = [NSArray arrayWithObjects:[NSValue valueWithCGPoint:point],[NSValue valueWithCGPoint:point1],[NSValue valueWithCGPoint:point2],[NSValue valueWithCGPoint:point3], nil];

NSIndexSet *set= [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, arr.count)];

//第二、就是这句话绘制

[arr enumerateObjectsAtIndexes:setoptions:0usingBlock:^(NSValue *pointValue, NSUInteger idx, BOOL *stop){

CGPoint point = [pointValue CGPointValue];[path addLineToPoint:point];

//(一)rect折线画法

CGRect rect;

rect.origin.x = point.x -1.5;

rect.origin.y = point.y -1.5;

rect.size.width =4;

rect.size.height =4;

//(二)rect射线画法

// CGRect rect = CGRectMake(10, 10, 1, 1);


UIBezierPath *arc= [UIBezierPath bezierPathWithOvalInRect:rect];[path appendPath:arc];    

}];


//第三、UIBezierPath和CAShapeLayer关联

CAShapeLayer *lineLayer = [CAShapeLayer layer];   

 lineLayer.frame = CGRectMake(0,150,320,400);   

 lineLayer.fillColor = [UIColor redColor].CGColor;   

 lineLayer.path = path.CGPath;   

 lineLayer.strokeColor = [UIColor redColor].CGColor;   

 [view.layer addSublayer:lineLayer];

//以下代码为附加的//(一)像一个幕布一样拉开,显得有动画

UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0,100,320,400)];    

view1.backgroundColor = [UIColor whiteColor];   

[self.view addSubview:view1];       

 [UIView animateWithDuration:5animations:^{

view1.frame = CGRectMake(320,100,320,400);   

 }]; }

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

相关阅读更多精彩内容

  • Quartz2D以及drawRect的重绘机制字数1487 阅读21 评论1 喜欢1一、什么是Quartz2D Q...
    PurpleWind阅读 4,286评论 0 3
  • 转至 http://blog.csdn.net/guo_hongjun1611/article/details/7...
    小地阅读 8,283评论 1 6
  • 使用UIBezierPath类可以创建基于矢量的路径,这个类在UIKit中。此类是Core Graphics框架关...
    MMOTE阅读 4,162评论 0 5
  • 对于一个女人最好的赞美,不是漂亮性感而是明白干净。 男人想出轨,跟你优不优秀没关系,即便你是仙女,他也会惦记别的青...
    不负杯中茶阅读 3,395评论 0 0
  • 今年寒假,我没有向以往一样去找熟人介绍寒假工,而且自己在一个西餐厅门口看到张贴的招聘小纸条,便兴致勃勃地进去了...
    风筝误追阅读 7,903评论 21 6

友情链接更多精彩内容