我想绘制一个垂直的单条形图。我试图使用DrawRect,但无法这样做。如果可以通过提供开始和结束点来改变颜色,可以轻松完成,那么就可以让我知道如何。
感谢
答案 0 :(得分:2)
如果您有自定义视图,则只需绘制所需的线条和矩形即可。例如:
- (void)drawRect:(CGRect)rect
{
CGAffineTransform t = CGAffineTransformMakeScale(1, -1);
self.transform = t;
CGFloat baseline = 50;
CGFloat inset = 40;
CGFloat barWidth = 20;
CGFloat barHeight = 80;
CGRect r = CGRectMake(inset + barWidth, baseline, barWidth, barHeight);
UIBezierPath *p = [UIBezierPath bezierPathWithRect:r];
[[UIColor redColor] set];
[p fill];
p = [UIBezierPath bezierPath];
[p moveToPoint:CGPointMake(inset, baseline)];
[p addLineToPoint:CGPointMake(inset + 3 * barWidth, baseline)];
[[UIColor blackColor] set];
[p stroke];
}
产生这个:
我使用上面的-drawRect:
方法创建了一个UIView子类,并创建了该视图的实例,该实例的大小与窗口大小相同。请注意,我使用变换来翻转坐标系 - 您不必这样做,但使用左下角的原点进行绘制可能更容易。
答案 1 :(得分:0)
尝试这一个 1. http://www.raywenderlich.com/13271/how-to-draw-graphs-with-core-plot-part-2
2 OVGraph.-图表库