美文网首页
ios 简单折线图

ios 简单折线图

作者: 听风赏花_fc3e | 来源:发表于2017-05-16 16:02 被阅读0次

缘分已到,这是一个简单的折线图,带阴影有点击事件,有刷新 ,回调写好了,不行就自己加点,改点吧,人之患好为人师,所以我就简单说两句啊~<😊>~。

我做的是这样事儿的

首先是贝尔曲线

///设置 起始点 到 移动点  这个只是路径

UIBezierPath*path = [UIBezierPathbezierPath];

[path moveToPoint:CGPointMake(GapBetweenX* t +tableX,0+tableY)];

[path addLineToPoint:CGPointMake(GapBetweenX* t +tableX,(_arrCoordinatesY.count-1)*GapBetweenY+tableY)];

[path closePath];

这个才是 路径展现出来的方法 

CAShapeLayer*shapeLayerX = [CAShapeLayer layer];

shapeLayerX.path= path.CGPath;

shapeLayerX.strokeColor= colorX.CGColor;

shapeLayerX.lineWidth=0.5;

[_scrollView.layer addSublayer:shapeLayerX];

其实这两段 就是 iOS 划线的核心方法了,折线图什么的修修改改就好了,再见。。。。。。。。。。。。

您能看到这儿就表明,道友你我有缘啊,再见👋。

好了,折线图 就是一条线,利用 moveToPoint:  和  addLineToPoint :  被分成好多段

大概就是这样

for(int t =0; t <_arrBrokenLine.count; t ++) {

CGFloat lineY = [[_arrBrokenLine objectAtIndex:t]floatValue];

CGFloat lineX =GapBetweenX*t +tableX;

CGFloat coordinatesY = (tableHight)/(maxY - minY) * (maxY - lineY) +tableY;

CGPoint point =CGPointMake(lineX , coordinatesY);

if(t !=_arrBrokenLine.count-1) {

CGFloatlineYNext = [[_arrBrokenLine objectAtIndex:t +1]floatValue] ;

CGFloat lineXNext =GapBetweenX* (t +1) +tableX;

CGFloat coordinatesYNext =tableHight/(maxY - minY) * (maxY - lineYNext) +tableY;

CGPoint pointNext =CGPointMake(lineXNext , coordinatesYNext );

[path addLineToPoint:pointNext];

[path moveToPoint:pointNext];

}

[pathLayer addLineToPoint:point];

if(t ==_arrBrokenLine.count-1) {

[pathLayer addLineToPoint:CGPointMake(point.x,_scrollView.contentSize.height-5)];

}

(好气啊,复制过来空格都没了)

想要加个动画如下

CABasicAnimation*pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];

pathAnimation.duration=2;

pathAnimation.timingFunction= [CAMediaTiming FunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];

pathAnimation.fromValue= [NSNumber numberWithFloat:0.0f];

pathAnimation.toValue= [NSNumber numberWithFloat:1.0f];

pathAnimation.autoreverses=NO;

pathAnimation.delegate=self;

[shapeLayerX addAnimation:pathAnimationforKey:@"strokeEndAnimation"];

shapeLayerX.strokeEnd=1.0;

如果你还想加个背景

///背景图layer

CAGradientLayer*gradLayer = [CAGradientLayerlayer];

gradLayer.frame=CGRectMake(0,0,_scrollView.contentSize.width,_scrollView.contentSize.height);

gradLayer.colors=@[(__bridgeid)RGBCOLOR_ALPHA(47,131,228,0.3).CGColor,(__bridgeid)RGBCOLOR_ALPHA(47,131,228,0.3).CGColor,(__bridgeid)RGBCOLOR_ALPHA(47,131,228,0.3).CGColor];

gradLayer.startPoint=CGPointMake(0,1);

gradLayer.endPoint=CGPointMake(0,1);

gradLayer.locations=@[@0.2,@0.5,@0.7];

[_scrollView.layeraddSublayer:gradLayer];

写了这么多 ,我估计也没有几个人会仔细看

注意这里放链接了,有兴趣的可以一起做些更好的动画特效什么的 github.com/zdqwsx/BrokenLine

差点忘记 祝我自己身体健康,明天就有美女表白。

相关文章

  • 简单iOS折线图

    先看效果图 所用框架 CAShapeLayer与UIBezierPath配合画线。画线的两种方法: DrawRec...

  • ios 简单折线图

    缘分已到,这是一个简单的折线图,带阴影有点击事件,有刷新 ,回调写好了,不行就自己加点,改点吧,人之患好为人师,所...

  • iOS绘图入门--手把手教你画折线图

    适用人群:iOS开发人员。本文内容:使用UIBezierPath和CAShareLayer绘制简单的折线图。 平常...

  • iOS开发--简单折线图

    作为一个iOS程序媛,还真是没有发文章的习惯,但是据说如果能够长期整理自己代码的心得,写成文章,那是可以证明实力的...

  • iOS 折线图的简单现实

    一、画出X,Y轴 二、分别给X坐标和Y坐标添加代表的属性值 三、画折线图 结果图

  • ECharts折线图

    上一节我们已经简单介绍过ECharts插件,也举过列子绘制简单的折线图 点我查看—绘制简单折线图 而在实际的应用中...

  • 【iOS】简单易用的折线图控件

    一个简单易用的折线图控件,最近项目工程中需要用到一个折现图,看了网上的一些例子,但都不能满足UED的特殊要求,所以...

  • python画hist直方图

    一、图形选择 简单说下图形选择啦,通常我们最常用的图形是折线图、扇形图、条形图,它们的功能简单概括为:折线图:表示...

  • matplotlib绘制折线图命令

    折线图,最简单的一种图形。 导入包: 生成fig: 生成折线图:plt.plot(横坐标,纵坐标)如: 显示: 修...

  • Excel技巧:诡异的折线图?折线图与XY散点图的区别

    碰到一个小伙伴的问题,是有关Excel折线图的制作。一看非常简单。 一看这数据很简单啊,插入折线图不就完了。动图操...

网友评论

      本文标题:ios 简单折线图

      本文链接:https://www.haomeiwen.com/subject/tiylxxtx.html