RDImageView.m 878 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // RDImageView.m
  3. //
  4. // Created by apple on 15/11/27.
  5. // Copyright (c) 2015年 apple. All rights reserved.
  6. //
  7. #import "RDImageView.h"
  8. @implementation RDImageView
  9. -(instancetype)initWithFrame:(CGRect)frame
  10. {
  11. self = [super initWithFrame:frame];
  12. if (self) {
  13. [self setBackgroundColor:[UIColor clearColor]];
  14. }
  15. return self;
  16. }
  17. -(void)drawRect:(CGRect)rect
  18. {
  19. //圆的线条宽度
  20. CGFloat lw ;
  21. lw = 0;
  22. if (_color) {
  23. lw = 3.5;
  24. }
  25. UIColor *col = _color;
  26. [col set];//设置线条颜色
  27. CGFloat d = self.frame.size.width * .8;
  28. CGFloat x = (self.frame.size.width - d)/2.0;
  29. UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(x, x, d, d)];
  30. path.lineWidth = lw;
  31. [path stroke];//空心的图形
  32. [path addClip];
  33. [_image drawInRect:self.bounds];
  34. }
  35. @end