简体   繁体   English

iPhone上的CoreGraphics,试图绘制“药丸”型椭圆

[英]CoreGraphics on iPhone, trying to draw a “pill” type ellipse

I'm trying to draw a pill type ellipse, as in Apple's Mail application which displays the number of emails in the inbox. 我正在尝试绘制一种药丸形状的椭圆形,如在Apple的Mail应用程序中那样,该应用程序在收件箱中显示电子邮件数量。 Any idea why the following isn't drawing? 知道为什么没有绘制以下内容吗?

- (void)drawRect:(CGRect)rect 
{ 
   CGContextRef context = UIGraphicsGetCurrentContext();

    CGFloat minX = CGRectGetMinX(rect);
    CGFloat minY = CGRectGetMinY(rect);
    CGFloat maxX = CGRectGetMaxX(rect);
    CGFloat maxY = CGRectGetMaxY(rect);

    CGFloat radius = 3.0; 
    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);

    CGContextDrawPath(context, kCGPathFill);
    CGContextFillPath(context);
}

I think you've forgotten to set the fill color. 我认为您已经忘记设置填充颜色了。

Also, see this question for code to do exactly what you require. 另外,请参见此问题以获取代码以完全满足您的要求。

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

相关问题 如何使用iPhone上的CoreGraphics逐像素绘制椭圆形像素 - How could I draw an ellipse pixel by pixel using CoreGraphics on iPhone 如何在iPhone(特别是iPad)上使用CoreGraphics绘制一个简单的椭圆? - How do I draw a simple ellipse using CoreGraphics on the iPhone (specifically iPad)? 在iphone中使用coregraphics绘制文本 - draw text using coregraphics in iphone 使用CoreGraphics在iPhone上绘制径向数据 - Draw radial data on iPhone using CoreGraphics 在iPhone应用程序中绘制椭圆的最佳方法是什么? - What is the best way to draw this ellipse in an iPhone app? iPhone,您如何使用 coregraphics 从纹理页面中绘制? - iPhone, how do you draw from a texturepage using coregraphics? 在iPhone OpenGL或Coregraphics中绘制光泽圆的最佳方法是什么? - What is the best way to draw a glossy circle in iPhone OpenGL or Coregraphics? 如何通过iphone中的时间间隔使用coregraphics快速绘制线条 - how to draw lines quickly using coregraphics via time intervals in iphone 我应该画椭圆形的核心图形还是只为我的2D游戏程序使用一些图像 - Should i draw coregraphics ellipse or just use some images for my 2D Game Program 尝试为每个笔划设置唯一的CoreGraphics(iphone)状态 - Trying to set unique CoreGraphics (iphone) States for each Stroke
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM