简体   繁体   中英

Updating UIView subclass contents

I am trying to update a UIView subclass to draw individual pixels (rectangles) after calculating if they are in the mandelbrot set.

I am using the following code but am getting a blank screen:

//drawingView.h

...

-(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);

}
...

//viewController.m
...
- (void)viewDidLoad {
    [drawingView setX:10];
    [drawingView setY:10];
    [drawingView setR:0.0];
    [drawingView setG:0.0];
    [drawingView setB:0.0];
    [super viewDidLoad];
    [drawingView setNeedsDisplay];
}

Once I figure out how to display one pixel, I'd like to know how to go about updating the view by adding another pixel (once calculated). Once all the variables change, how do I keep the current view as is but add another pixel?

Thanks, Brett

CGContextMoveToPoint(context, xcoord, ycoord);
CGContextAddLineToPoint(context, xcoord, ycoord);
CGContextStrokePath(context);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM