MJButton.m 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // MJButton.m
  3. //
  4. // Created by 123 on 2020/5/8.
  5. // Copyright © 2020 Vibration Fly. All rights reserved.
  6. //
  7. #import "MJButton.h"
  8. #import "UIView+LK.h"
  9. @implementation MJButton
  10. /*
  11. // Only override drawRect: if you perform custom drawing.
  12. // An empty implementation adversely affects performance during animation.
  13. - (void)drawRect:(CGRect)rect {
  14. // Drawing code
  15. }
  16. */
  17. -(instancetype)initWithFrame:(CGRect)frame{
  18. if (self=[super initWithFrame:frame]) {
  19. [self setTitleColor:kRGBColor(51, 51, 51) forState:UIControlStateNormal];
  20. self.titleLabel.font= [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  21. }
  22. return self;
  23. }
  24. - (void)layoutSubviews{
  25. [super layoutSubviews];
  26. if (_typeBtn==1) {
  27. self.titleLabel.font= [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
  28. CGRect titleF = self.titleLabel.frame;
  29. CGRect imageF = self.imageView.frame;
  30. titleF.origin.x = 0;
  31. self.titleLabel.frame = titleF;
  32. imageF.origin.x = CGRectGetMaxX(titleF);
  33. self.imageView.frame = imageF;
  34. }else{
  35. self.imageView.xmg_y=2;
  36. self.imageView.xmg_x=(self.xmg_width-self.imageView.xmg_width)/2;
  37. self.titleLabel.xmg_y=CGRectGetMaxY(self.imageView.frame)+8;
  38. self.titleLabel.xmg_width=self.xmg_width;
  39. self.titleLabel.xmg_x=0;
  40. self.titleLabel.textAlignment=NSTextAlignmentCenter;
  41. }
  42. }
  43. @end