Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

You can also use CGContextClearRect(context, CGRectMake(0, 0, width, height));

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top