UIImage+PKDownloadButton.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // UIImage+PKDownloadButton.m
  3. // Download
  4. //
  5. // Created by Pavel on 31/05/15.
  6. // Copyright (c) 2015 Katunin. All rights reserved.
  7. //
  8. #import "UIImage+PKDownloadButton.h"
  9. @implementation UIImage (PKDownloadButton)
  10. + (UIImage *)stopImageOfSize:(CGFloat)size color:(UIColor *)color {
  11. UIGraphicsBeginImageContextWithOptions(CGSizeMake(size, size), NO, 1.0f);
  12. CGContextRef context = UIGraphicsGetCurrentContext();
  13. [color setStroke];
  14. CGRect stopImageRect = CGRectMake(0.f, 0.f, size, size);
  15. CGContextSetFillColorWithColor(context, color.CGColor);
  16. CGContextAddRect(context, stopImageRect);
  17. CGContextFillRect(context, stopImageRect);
  18. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  19. UIGraphicsEndImageContext();
  20. return image;
  21. }
  22. + (UIImage *)borderedImageWithFill:(UIColor *)fillColor radius:(CGFloat)radius lineColor:(UIColor *)lineColor lineWidth:(CGFloat)lineWidth {
  23. UIGraphicsBeginImageContextWithOptions(CGSizeMake(radius * 2, radius * 2), NO, 0.0f);
  24. UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(lineWidth,lineWidth,(radius - lineWidth) * 2, (radius - lineWidth) * 2)
  25. cornerRadius:radius];
  26. bezierPath.lineWidth = lineWidth;
  27. if (lineColor) [lineColor setStroke];
  28. if (fillColor) [fillColor setFill];
  29. [bezierPath stroke];
  30. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  31. UIGraphicsEndImageContext();
  32. return [image resizableImageWithCapInsets:UIEdgeInsetsMake(radius, radius, radius, radius)];
  33. }
  34. @end