iPhone CGContext: drawing two lines with two different colors

前端 未结 4 1301
终归单人心
终归单人心 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:13

    I think this could be working.

    CGContextRef bluecontext = UIGraphicsGetCurrentContext(); 
    CGContextSetLineWidth(bluecontext, 2.0);
    CGContextSetStrokeColorWithColor(bluecontext, [UIColor blueColor].CGColor);
    CGContextMoveToPoint(bluecontext, 1, 1);
    CGContextAddLineToPoint(bluecontext, 100, 100);
    
    CGContextStrokePath(bluecontext); // draw blue line
    
    
    CGContextSetStrokeColorWithColor(bluecontext, [UIColor redColor].CGColor);
    CGContextAddLineToPoint(bluecontext, 200, 100);
    
    CGContextStrokePath(bluecontext); // and draw red line
    

提交回复
热议问题