UIGraphicsPushContext, UIGraphicsPopContext

Hi fellow Nerds… I’m pulling my hair out. I want to make sure I understand the subject calls. Below is may example that is NOT working as hoped.

Summary: I want to draw three lines. Two lines are of width 5. and drawn from drawRect. A single line of width 25. is drawn from the drawBigLine method.

My code returns three lines. The last two lines drawn are of width 25. I was expecting the UIGraphicsPopContext to return me back to the context with lineWidth value of 5. That is not happening. It seems that UIGraphicsPopContext is not popping.

Any ideas of what I’m doing wrong?

Much Thanks – Ron

@implementation RLView

  • (void)drawRect:(CGRect)rect
    CGContextRef ctx=UIGraphicsGetCurrentContext();
    CGContextMoveToPoint(ctx, 100., 100.);
    CGContextAddLineToPoint(ctx, 200., 200.);
    CGContextSetLineWidth(ctx, 5.);
    CGContextDrawPath(ctx, kCGPathStroke);

    [self drawBigLine:ctx];

    CGContextMoveToPoint(ctx, 300., 10.);
    CGContextAddLineToPoint(ctx, 300., 300.);
    CGContextDrawPath(ctx, kCGPathStroke);



CGContextMoveToPoint(context, 30., 30.);
CGContextAddLineToPoint(context, 90., 90.);
CGContextSetLineWidth(context, 25.);
CGContextDrawPath(context, kCGPathStroke);




If I add the following:

[self drawBigLine:ctx];

all works as expected.