Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. func drawDisk(color: UIColor, rectForDisk: CGRect = CGRectMake(0.0, 0.0, 1.0, 1.0), withStroke: Bool) -> UIImage {
  2. UIGraphicsBeginImageContextWithOptions(rectForDisk.size, false, 0.0)
  3. let context = UIGraphicsGetCurrentContext()
  4.  
  5. CGContextSetFillColorWithColor(context, color.CGColor)
  6. CGContextFillEllipseInRect(context, rectForDisk)
  7.  
  8. let rectForCircle = CGRectMake(0.5, 0.5, rectForDisk.size.width - 1, rectForDisk.size.height - 1)
  9. CGContextSetLineWidth(context, withStroke ? 1.0 : 0)
  10. CGContextSetStrokeColorWithColor(context,
  11. UIColor.blackColor().CGColor)
  12. CGContextAddEllipseInRect(context, rectForCircle)
  13. CGContextStrokePath(context)
  14.  
  15. let image = UIGraphicsGetImageFromCurrentImageContext()
  16. UIGraphicsEndImageContext()
  17.  
  18. return image
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement