What is the best way to draw this ellipse in an iPhone app?

I would like to have a similar ellipse as the Mail app in my iPhone app. A screenshot for reference is here: http://dl-client.getdropbox.com/u/57676/screenshots/ellipse.png

In the end, I would like the ellipse to have a numerical value centered in it. Is it better to use UIImage to accomplish this task? Perhaps less overhead to draw it with quartz? If this is done with Quartz, can someone display a solution for drawing it?

+3
source share
1 answer

A rounded rectangle. This is not too difficult to do. You can use Bezier paths to get what you want. The code is as follows:

CGRect rect;
CGFloat minX = CGRectGetMinX(rect), minY = CGFloatGetMinY(rect), maxX = CGFloatGetMaxX(rect), maxY = CGRectGetMaxY(rect);

CGFloat radius = 3.0; // Adjust as you like
CGContextBeginPath(context);
CGContextMoveToPoint(context, (minX + maxX) / 2.0, minY);
CGContextAddArcToPoint(context, minX, minY, minX, maxY, radius);
CGContextAddArcToPoint(context, minX, maxY, maxX, maxY, radius);
CGContextAddArcToPoint(context, maxX, maxY, maxX, minY, radius);
CGContextAddArcToPoint(context, maxX, minY, minX, minY, radius);
CGContextClosePath(context);

Now that you have the path to the graphics context, you can draw it or draw it using the CGContextDrawPathand functions CGContextFillPath.

+9
source

Source: https://habr.com/ru/post/1705814/


All Articles