// // MJButton.m // // Created by 123 on 2020/5/8. // Copyright © 2020 Vibration Fly. All rights reserved. // #import "MJButton.h" #import "UIView+LK.h" @implementation MJButton /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ -(instancetype)initWithFrame:(CGRect)frame{ if (self=[super initWithFrame:frame]) { [self setTitleColor:kRGBColor(51, 51, 51) forState:UIControlStateNormal]; self.titleLabel.font= [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]; } return self; } - (void)layoutSubviews{ [super layoutSubviews]; if (_typeBtn==1) { self.titleLabel.font= [UIFont systemFontOfSize:12 weight:UIFontWeightMedium]; CGRect titleF = self.titleLabel.frame; CGRect imageF = self.imageView.frame; titleF.origin.x = 0; self.titleLabel.frame = titleF; imageF.origin.x = CGRectGetMaxX(titleF); self.imageView.frame = imageF; }else{ self.imageView.xmg_y=2; self.imageView.xmg_x=(self.xmg_width-self.imageView.xmg_width)/2; self.titleLabel.xmg_y=CGRectGetMaxY(self.imageView.frame)+8; self.titleLabel.xmg_width=self.xmg_width; self.titleLabel.xmg_x=0; self.titleLabel.textAlignment=NSTextAlignmentCenter; } } @end