title: Drawing rounded rect in core graphics
body: <p>I want to replicate the event markers of the default iPad calendar, which look like this:</p>
  
  <p><img src="https://i.stack.imgur.com/Ik2wp.png" alt="enter image description here">
  I'm trying to use coregraphics for this, painting a path of a rounded rect. This is the result I could come up with:</p>
  
  <p><img src="https://i.stack.imgur.com/bHWx1.png" alt="enter image description here"></p>
  
  <p>As you can see, iPad's version looks much smoother on the rounded corners. I tried to use a bigger line width, which looks like this:
  <img src="https://i.stack.imgur.com/3Jr5i.png" alt="enter image description here"></p>
  
  <p>My code looks like this (got it from this website):</p>
  
  <pre><code>UIColor* fillColor= [self.color colorByMultiplyingByRed:1 green:1 blue:1 alpha:0.2];
  
  CGContextSetLineWidth(ctx, 1.0);
  CGContextSetStrokeColorWithColor(ctx, self.color.CGColor);
  CGContextSetFillColorWithColor(ctx, fillColor.CGColor);
  
  CGRect rrect = self.bounds;
  
  CGFloat radius = 30.0;
  CGFloat width = CGRectGetWidth(rrect);
  CGFloat height = CGRectGetHeight(rrect);
  
  if (radius &gt; width/2.0)
     radius = width/2.0;
  
  if (radius &gt; height/2.0)
     radius = height/2.0;    
  
  CGFloat minx = CGRectGetMinX(rrect);
  CGFloat midx = CGRectGetMidX(rrect);
  CGFloat maxx = CGRectGetMaxX(rrect);
  CGFloat miny = CGRectGetMinY(rrect);
  CGFloat midy = CGRectGetMidY(rrect);
  CGFloat maxy = CGRectGetMaxY(rrect);
  CGContextMoveToPoint(ctx, minx, midy);
  CGContextAddArcToPoint(ctx, minx, miny, midx, miny, radius);
  CGContextAddArcToPoint(ctx, maxx, miny, maxx, midy, radius);
  
  CGContextAddArcToPoint(ctx, maxx, maxy, midx, maxy, radius);
  CGContextAddArcToPoint(ctx, minx, maxy, minx, midy, radius);
  CGContextClosePath(ctx);
  CGContextDrawPath(ctx, kCGPathFillStroke);
  
  // draw circle on left side
  
  CGRect target= CGRectMake(rect.origin.x + 4.0, 
                            rect.origin.y + 3.0, 
                            7.0, 7.0);
  
  CGContextSetFillColorWithColor(ctx, self.color.CGColor);
  CGContextSetAlpha(ctx, 0.4);
  CGContextFillEllipseInRect(ctx, target);
  
  CGContextSetAlpha(ctx, 0.9);
  CGContextSetStrokeColorWithColor(ctx, self.color.CGColor);
  CGContextStrokeEllipseInRect(ctx, target);
  </code></pre>
  
  <p>Can anyone help me to bring the results closer to the original? Should I use a different technique to paint the rounded rect, or are there any parameters I can change to make it look smoother?
  I already tried using a <code>UIBezierPath</code>, but it basically looked the same. Any tips?</p>
  
  <p>[edit] The <code>CGRectInset</code>-based solution looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/CxKWn.png" alt="enter image description here"></p>