【问题标题】:Draw lines without the -(void)drawRect:(CGRect)rect method?没有 -(void)drawRect:(CGRect)rect 方法画线?
【发布时间】:2014-08-28 11:31:12
【问题描述】:

我想在 UIView 中制作一个图表。像这样的东西:

有没有比使用这种方法更简单的方法来绘制线条:

-(void)drawRect:(CGRect)rect{

    [super drawRect:rect];

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);

    // Draw them with a 2.0 stroke width so they are a bit more visible.
    CGContextSetLineWidth(context, 2.0f);

    CGContextMoveToPoint(context, 0.0f, 0.0f); //start at this point

    CGContextAddLineToPoint(context, 20.0f, 20.0f); //draw to this point

    // and now draw the Path!
    CGContextStrokePath(context);
}

?

【问题讨论】:

  • 试试PCLineChartView link,画这样的图表的简单方法
  • 好的,谢谢,我去看看。

标签: ios iphone xcode uiview


【解决方案1】:

你可以尝试使用UIBezierPath类:

UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:startPoint];
[path addLineToPoint:endPoint];
[path stroke];

如果需要绘制图表,请尝试使用CorePlot - 绘图框架。

【讨论】:

    【解决方案2】:

    为什么不试试UIBezierPath Apple 的高级实现。

    更多信息请参考UIBezierPath - Apple Doc

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多