KKScaleButton.m 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // KKScaleButton.m
  3. // WWImageEdit
  4. //
  5. // Created by 邬维 on 2017/1/13.
  6. // Copyright © 2017年 kook. All rights reserved.
  7. //
  8. #import "KKScaleButton.h"
  9. @implementation KKScaleButton
  10. - (id)initWithFrame:(CGRect)frame
  11. {
  12. self = [super initWithFrame:frame];
  13. if (self) {
  14. self.backgroundColor = [UIColor clearColor];
  15. }
  16. return self;
  17. }
  18. - (void)drawRect:(CGRect)rect
  19. {
  20. CGContextRef context = UIGraphicsGetCurrentContext();
  21. CGRect rct = self.bounds;
  22. CGFloat radius = 0.7;
  23. rct.origin.x = 0.5 * (rct.size.width - radius * rct.size.width);
  24. rct.origin.y = 0.5 * (rct.size.height - radius * rct.size.height);
  25. rct.size.width = radius * rct.size.width;
  26. rct.size.height = radius * rct.size.height;
  27. CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
  28. CGContextFillEllipseInRect(context, rct);
  29. CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
  30. CGContextSetLineWidth(context, 5);
  31. CGContextStrokeEllipseInRect(context, rct);
  32. }
  33. @end