简体   繁体   English

在iPhone应用程序中绘制椭圆的最佳方法是什么?

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

I'd like to have a similar ellipse as the Mail app in my iPhone app. 我想在我的iPhone应用程序中使用与Mail应用程序类似的椭圆。 A screenshot just for reference is here: http://dl-client.getdropbox.com/u/57676/screenshots/ellipse.png 仅供参考的屏幕截图如下: http//dl-client.getdropbox.com/u/57676/screenshots/ellipse.png

Ultimately I'd like the ellipse with a numerical value centered in it. 最后,我想要一个以数值为中心的椭圆。 Is it best to use a UIImage for this task? 是否最好使用UIImage执行此任务? Perhaps less overhead to draw it with Quartz? 使用Quartz绘制它的开销可能更少? If it's done with Quartz, can anyone display a solution for drawing it? 如果它是用Quartz完成的,那么任何人都可以显示绘制它的解决方案吗?

Ah, a rounded rectangle. 啊,圆角矩形。 That's not too hard to draw. 这不是很难画。 You can use Bezier paths to get what you want. 您可以使用Bezier路径获得所需内容。 The code looks like this: 代码如下所示:

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 a path on your graphics context, you can draw it or outline it using the CGContextDrawPath and CGContextFillPath functions. 现在您的图形上下文中有一个路径,您可以使用CGContextDrawPathCGContextFillPath函数绘制它或勾勒它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 保存iPhone应用程序设置的最佳方法是什么? - What is the best way to save iphone app settings? 编写混合iPhone应用程序的最佳方法是什么? - What is the best way to write a hybrid iPhone app? 更新iPhone应用程序数据的最佳方法是什么? - What is the best way to update data for an iPhone app? 在iPhone OpenGL或Coregraphics中绘制光泽圆的最佳方法是什么? - What is the best way to draw a glossy circle in iPhone OpenGL or Coregraphics? 从iPhone应用程序进行网页抓取的最佳方法是什么? - What is the best way to do web scraping from an iPhone App? 将图像从服务器传输到iPhone应用程序的最佳方法是什么? - What is the best way to transfer images from a server to an iPhone app? 在iphone应用程序中记录调试信息的最佳方法是什么? - What's the best way to log debug info in an iphone app? 将iphone应用程序连接到mysql数据库的最佳方法是什么? - What is the best way to connect an iphone app to a mysql database? 在iPhone应用程序中存储(可能是数百个)字符串的最佳方法是什么? - What is the best way to store (possibly hundreds) of strings in iPhone app? 在iPhone App中提供小图像选择的最佳方法是什么? - What would be the best way of providing small image selection in an iPhone App?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM