我想创建一个简单的线形图,就像下面这个例子一样:
我通过谷歌搜索找到了CorePlot,但它看起来太复杂了。有人能建议我如何创建类似下面这样的线形图吗?或者教程也可以。谢谢。
![enter image description here](https://istack.dev59.com/luW3l.webp)
-(void)drawLineFromX:(CGPoint)topPoint{
UIGraphicsBeginImageContext(instanceToYourImageView.image.size);
[instanceToYourImageView.image drawInRect:CGRectMake(0, 0, instanceToYourImageView.image.size.width, instanceToYourImageView.image.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), topPoint.x, topPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), topPoint.x, topPoint.y + a_value_to_reach_the_base_line);
CGContextStrokePath(UIGraphicsGetCurrentContext());
[instanceToYourImageView setImage:UIGraphicsGetImageFromCurrentImageContext()];
UIGraphicsEndImageContext();
}
这里的CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
是黑色的,但你可以轻松地将其更改为所需的颜色。
干杯!