// // WHMineSwitchView.m // MSYOUPAI // // Created by 刘必果 on 2024/2/1. // Copyright © 2024 MS. All rights reserved. // #import "WHMineSwitchView.h" @implementation WHMineSwitchView - (instancetype)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if(self){ [self initUI]; [self loadLayout]; [self setBackgroundColor:[UIColor clearColor]]; [self mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(WHScreenEqualWidth(56)); }]; } return self; } - (void)setDict:(NSDictionary *)dict{ _dict = dict; [self.logImageView setImage:dict[@"image"]]; [self.titleLab setText:dict[@"title"]]; } - (void)initUI{ [self addSubview:self.logImageView]; [self addSubview:self.titleLab]; [self addSubview:self.switchView]; } - (void)loadLayout{ [self.logImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.height.mas_equalTo(WHScreenEqualWidth(24)); make.left.equalTo(self).offset(WHScreenEqualWidth(15)); make.centerY.equalTo(self); }]; [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self); make.left.equalTo(self.logImageView.mas_right).offset(WHScreenEqualWidth(15)); }]; [self.switchView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(WHScreenEqualWidth(36)); make.height.mas_equalTo(WHScreenEqualWidth(20)); make.centerY.equalTo(self); make.right.equalTo(self).offset(WHScreenEqualWidth(-15)); }]; } #pragma mark - get set - (UIImageView *)logImageView{ if(!_logImageView){ _logImageView = [UIImageView new]; } return _logImageView; } - (UILabel *)titleLab{ if(!_titleLab){ _titleLab = [[UILabel alloc] init]; [_titleLab setText:@"查看开通会员10大权益"]; [_titleLab setFont:[UIFont systemFontOfSize:WHScreenEqualWidth(16)]]; [_titleLab setTextColor:HexColorFromRGB(0x171A1D)]; } return _titleLab; } - (UISwitch *)switchView{ if(!_switchView){ _switchView = [[UIButton alloc] init]; [_switchView setImage:[UIImage imageNamed:@"mine_switch_press"] forState:UIControlStateSelected]; [_switchView setImage:[UIImage imageNamed:@"mine_switch_def"] forState:UIControlStateNormal]; } return _switchView; } @end