EXButton.m 944 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #import "EXButton.h"
  2. @implementation EXButton
  3. -(id)initWithFrame:(CGRect)frame
  4. {
  5. self = [super initWithFrame:frame];
  6. if (self) {
  7. [self.titleLabel setTextAlignment:NSTextAlignmentCenter];
  8. }
  9. return self;
  10. }
  11. -(void)drawRect:(CGRect)rect
  12. {
  13. //画贝塞尔曲线之类的
  14. CGFloat lw = 2.0;
  15. UIColor *color = KlineColor;
  16. [color set];//设置线条颜色
  17. CGFloat d = self.frame.size.width * .8;
  18. CGFloat x = (self.width - d)/2.0;
  19. UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(x, x, d, d)];
  20. path.lineWidth = lw;
  21. [path stroke];//空心的图形
  22. }
  23. -(CGRect)imageRectForContentRect:(CGRect)contentRect
  24. {
  25. CGFloat d = self.width * .8;
  26. CGFloat x = (self.width - d)/2.0;
  27. return CGRectMake(x, x, d, d);
  28. }
  29. -(CGRect)titleRectForContentRect:(CGRect)contentRect
  30. {
  31. return self.bounds;
  32. }
  33. @end
  34. /**
  35. 往btn里面加图片如何。
  36. */