iPhone CGContext: drawing two lines with two different colors

前端 未结 4 1207
终归单人心
终归单人心 2021-02-05 21:41

I am having some troubles using the CGContext with an iPhone app. I am trying to draw several lines with different colors, but all the lines always end up having the color which

4条回答
  •  面向向阳花
    2021-02-05 22:18

    Thats what you need.

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextClearRect(context, rect);
    CGContextSetLineWidth(context, 2.0);
    
    CGContextBeginPath(context);
    CGContextSetStrokeColorWithColor(context, [UIColor orangeColor].CGColor);
    CGContextMoveToPoint(context, 1, 1);
    CGContextAddLineToPoint(context, 100, 100);
    CGContextStrokePath(context); // and draw orange line}
    
    CGContextBeginPath(context);
    CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
    CGContextMoveToPoint(context, 100, 100);
    CGContextAddLineToPoint(context, 200, 100);     
    CGContextStrokePath(context); // draw blue line
    

提交回复
热议问题