iOS简单画折线图

来源:互联网 发布:java编写管理系统 编辑:程序博客网 时间:2024/06/09 23:40
- (void)drawRect:(CGRect)rect{    CGContextRef context = UIGraphicsGetCurrentContext();    [[UIColor redColor] setStroke];    CGContextSetLineWidth(context, 5);    CGPoint points[5];    points[0] = CGPointMake(100, 30);    points[1] = CGPointMake(120, 130);    points[2] = CGPointMake(140, 30);    points[3] = CGPointMake(160, 80);    points[4] = CGPointMake(180, 100);    CGContextAddLines(context, points, 5);    CGContextStrokePath(context);        for (int i = 0; i < 5; i ++) {        CGRect ellipseRect = CGRectMake(points[i].x - 3, points[i].y - 3, 8, 8);        CGContextAddEllipseInRect(context, ellipseRect);        CGContextSetLineWidth(context, 2);        [[UIColor whiteColor] setStroke];        [[UIColor blackColor] setFill];        CGContextFillEllipseInRect(context, ellipseRect);        CGContextStrokeEllipseInRect(context, ellipseRect);    }}


0 1