Update a portion UIView

Posted by Brett on Stack Overflow See other posts from Stack Overflow or by Brett
Published on 2010-06-16T15:07:51Z Indexed on 2010/06/16 15:12 UTC
Read the original article Hit count: 212

Hi;

I'm using -setNeedsDisplayinRect to update only a part of my UIView. However, all of my drawing done previously to calling this method is erased.

Here is my code in the UIView subclass:

-(void)drawRect:(CGRect)rect{

    CGContextRef context = UIGraphicsGetCurrentContext(); 

    CGContextSetRGBFillColor(context, r, g, b, 1);
    CGContextSetRGBStrokeColor(context, r, g, b, 1);

    CGRect arect = CGRectMake(x,y,1,1);


    CGContextFillRect(context, arect);


    NSLog(@"drawing");

}

and in the view controller:

-(void)drawView{

    drawingView = [[DrawingView alloc]init];

    x=10;
    y=10;
    r=0;
    g=0;
    b=0;

    [drawingView setNeedsDisplayInRect:CGRectMake(x, y, 1, 1)];

    x=20;
    y=20;
    r=0;
    g=0;
    b=0;


    [drawingView setNeedsDisplayInRect:CGRectMake(x, y, 1, 1)];
}

I end up with a screen where there is only one pixel at 20,20. Any help with this is so much appreciated. I am a beginner with XCode and am trying to complete a class project asap.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about xcode