Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are at least two approaches:</p> <ol> <li><p>Add QuartzCore.framework to your project, create a <code>UIBezierPath</code>, then create <code>CAShapeLayer</code> specifying its path, and then add the <code>CAShapeLayer</code> as a sublayer of your current view's layer. For example, I could call this from my view controller:</p> <pre><code>#import &lt;QuartzCore/QuartzCore.h&gt; - (void)addCircle { UIBezierPath *path = [UIBezierPath bezierPath]; [path addArcWithCenter:CGPointMake(self.view.layer.bounds.size.width / 2.0, self.view.layer.bounds.size.height / 2.0) radius:self.view.layer.bounds.size.width * 0.40 startAngle:0.0 endAngle:M_PI * 2.0 clockwise:YES]; CAShapeLayer *layer = [CAShapeLayer layer]; layer.path = [path CGPath]; layer.strokeColor = [[UIColor darkGrayColor] CGColor]; layer.fillColor = [[UIColor lightGrayColor] CGColor]; layer.lineWidth = 3.0; [self.view.layer addSublayer:layer]; } </code></pre></li> <li><p>Subclass <code>UIView</code> and override <code>drawRect</code> to draw the circle with Core Graphics.</p> <pre><code>@implementation CircleView - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextAddArc(context, self.bounds.size.width / 2.0, self.bounds.size.height / 2.0, self.bounds.size.width * 0.40, 0, M_PI * 2.0, YES); CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]); CGContextSetFillColorWithColor(context, [[UIColor blueColor] CGColor]); CGContextSetLineWidth(context, 3.0); CGContextDrawPath(context, kCGPathFillStroke); } @end </code></pre></li> </ol> <p>Both are valid. If you're not used to subclassing <code>UIView</code>, the former technique is probably easier.</p> <h3>References</h3> <p>The <a href="https://developer.apple.com/library/ios/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/Introduction/Introduction.html" rel="nofollow">Quartz 2D Programming Guide</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload