views:

1740

answers:

1

In my iPhone project, I've got a UIView where I implement the drawRect method:

- (void)drawRect:(CGRect)rect {
    CGContextRef context = UIGraphicsGetCurrentContext();

Inside the method I do a whole bunch of drawing of lines, images and texts using this context. The problem is that when I re-use this view, the context does not get reset. Is there a method I can call to reset the context somehow?

+8  A: 

You might want to check out CGContextSaveGState(context) and CGContextRestoreGState(context). They will let you push and pop the current state of the context.

If your view is getting 'mangled', check your view's contentMode setting.

Ben Gottlieb