Valentin
Valentin

Reputation: 3302

Drawing 100+ circles with different position using UIBezierPaths

I am trying to draw 100+ UIBezierPath circles in the drawRect function of an UIView. I am creating and adding the UIBezierPaths to an array:

for (int i = 0; i < 100; i++) {

    UIBezierPath *path = [UIBezierPath bezierPath];
    [path addArcWithCenter:centerPoint radius:10 startAngle:0 endAngle:360 clockwise:YES];

    path.lineWidth = 2;
    [bezierPaths addObject:path];
}

before calling the setNeedDisplay. Then in drawRect I iterate through the array

- (void)drawRect:(CGRect)rect {

       for (UIBezierPath *path in bezierPaths) {
            [path fill];
            [path stroke];
       }
    }

This looks like an overkill, is there a better way of doing this? Using Profile I can see that the 86% of the MainThread is being used on calling the [path stroke] in drawRect.

Upvotes: 0

Views: 146

Answers (1)

Valentin
Valentin

Reputation: 3302

I am passing 0 and 360 degrees as opposed to radiants and it is drawing them too many times.

Upvotes: 0

Related Questions