WHMineSwitchView.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // WHMineSwitchView.m
  3. // MSYOUPAI
  4. //
  5. // Created by 刘必果 on 2024/2/1.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "WHMineSwitchView.h"
  9. @implementation WHMineSwitchView
  10. - (instancetype)initWithFrame:(CGRect)frame{
  11. self = [super initWithFrame:frame];
  12. if(self){
  13. [self initUI];
  14. [self loadLayout];
  15. [self setBackgroundColor:[UIColor clearColor]];
  16. [self mas_makeConstraints:^(MASConstraintMaker *make) {
  17. make.height.mas_equalTo(WHScreenEqualWidth(56));
  18. }];
  19. }
  20. return self;
  21. }
  22. - (void)setDict:(NSDictionary *)dict{
  23. _dict = dict;
  24. [self.logImageView setImage:dict[@"image"]];
  25. [self.titleLab setText:dict[@"title"]];
  26. }
  27. - (void)initUI{
  28. [self addSubview:self.logImageView];
  29. [self addSubview:self.titleLab];
  30. [self addSubview:self.switchView];
  31. }
  32. - (void)loadLayout{
  33. [self.logImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.width.height.mas_equalTo(WHScreenEqualWidth(24));
  35. make.left.equalTo(self).offset(WHScreenEqualWidth(15));
  36. make.centerY.equalTo(self);
  37. }];
  38. [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.centerY.equalTo(self);
  40. make.left.equalTo(self.logImageView.mas_right).offset(WHScreenEqualWidth(15));
  41. }];
  42. [self.switchView mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.width.mas_equalTo(WHScreenEqualWidth(36));
  44. make.height.mas_equalTo(WHScreenEqualWidth(20));
  45. make.centerY.equalTo(self);
  46. make.right.equalTo(self).offset(WHScreenEqualWidth(-15));
  47. }];
  48. }
  49. #pragma mark - get set
  50. - (UIImageView *)logImageView{
  51. if(!_logImageView){
  52. _logImageView = [UIImageView new];
  53. }
  54. return _logImageView;
  55. }
  56. - (UILabel *)titleLab{
  57. if(!_titleLab){
  58. _titleLab = [[UILabel alloc] init];
  59. [_titleLab setText:@"查看开通会员10大权益"];
  60. [_titleLab setFont:[UIFont systemFontOfSize:WHScreenEqualWidth(16)]];
  61. [_titleLab setTextColor:HexColorFromRGB(0x171A1D)];
  62. }
  63. return _titleLab;
  64. }
  65. - (UISwitch *)switchView{
  66. if(!_switchView){
  67. _switchView = [[UIButton alloc] init];
  68. [_switchView setImage:[UIImage imageNamed:@"mine_switch_press"] forState:UIControlStateSelected];
  69. [_switchView setImage:[UIImage imageNamed:@"mine_switch_def"] forState:UIControlStateNormal];
  70. }
  71. return _switchView;
  72. }
  73. @end