Draw round rect with CoreGraphics


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. void CGContextAddRoundRect(CGContextRef context, CGRect rect, float radius)
  2. {
  3. CGContextRef context = UIGraphicsGetCurrentContext();
  4. [[UIColor whiteColor] set];
  5. CGContextMoveToPoint(context, rect.origin.x, rect.origin.y + radius);
  6. CGContextAddLineToPoint(context, rect.origin.x, rect.origin.y + rect.size.height - radius);
  7. CGContextAddArc(context, rect.origin.x + radius, rect.origin.y + rect.size.height - radius,
  8. radius, M_PI / 4, M_PI / 2, 1);
  9. CGContextAddLineToPoint(context, rect.origin.x + rect.size.width - radius,
  10. rect.origin.y + rect.size.height);
  11. CGContextAddArc(context, rect.origin.x + rect.size.width - radius,
  12. rect.origin.y + rect.size.height - radius, radius, M_PI / 2, 0.0f, 1);
  13. CGContextAddLineToPoint(context, rect.origin.x + rect.size.width, rect.origin.y + radius);
  14. CGContextAddArc(context, rect.origin.x + rect.size.width - radius, rect.origin.y + radius,
  15. radius, 0.0f, -M_PI / 2, 1);
  16. CGContextAddLineToPoint(context, rect.origin.x + radius, rect.origin.y);
  17. CGContextAddArc(context, rect.origin.x + radius, rect.origin.y + radius, radius,
  18. -M_PI / 2, M_PI, 1);
  19. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.