Tuesday, 20 August 2013

What is the best technique to render circles in iOS?

What is the best technique to render circles in iOS?

When rendering opaque non-gradient circular shapes of uniform color in
iOS, there seem to be three possible techniques:
Using images like circle-icon.png and circle-icon@2px.png. Then, one may
implement the following code to have iOS automagically render the
appropriate size:
UIImage *image = [UIImage imageNamed:@"circle-icon"];
self.closeIcon = [[UIImageView alloc] initWithImage:image];
self.closeIcon.frame = CGRectMake(300, 16, image.size.width,
image.size.height);
Rendering rounded corners and using layers, like so:.
self.circleView = [[UIView alloc] initWithFrame:CGRectMake(10,20,100,100)];
circleView.alpha = 0.5;
self.circleView.layer.cornerRadius = 50;
self.circleView.backgroundColor = [UIColor blueColor];
Using the native drawing libraries, with something like
CGContextFillEllipseInRect
What are the exact performance and maintenance tradeoffs of these 3
approaches?

No comments:

Post a Comment