YOUPAILZVipSetterCell.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // YOUPAILZVipSetterCell.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/8/21.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZVipSetterCell.h"
  9. @interface YOUPAILZVipSetterCell ()
  10. @property (nonatomic,weak) UILabel *youpaiptitleL;
  11. @property (nonatomic,weak) UILabel *youpaipdescL;
  12. @property (nonatomic,weak) UIButton *youpaipswitchBtn;
  13. @property (nonatomic,strong) YOUPAILZVipSetterModel *youpaipmodel;
  14. @end
  15. @implementation YOUPAILZVipSetterCell
  16. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  17. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  18. self.selectionStyle = UITableViewCellSelectionStyleNone;
  19. self.backgroundColor = [UIColor whiteColor];
  20. [self youpaifinitUI];
  21. }
  22. return self;
  23. }
  24. - (void)youpaifinitUI{
  25. UIButton *switchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  26. [switchBtn setImage:[UIImage imageNamed:@"vqu_images_ic_profile_siwch_on"] forState:UIControlStateSelected];
  27. [switchBtn setImage:[UIImage imageNamed:@"vqu_images_ic_profile_siwch_off"] forState:UIControlStateNormal];
  28. [switchBtn addTarget:self action:@selector(youpaifswitchBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  29. [self.contentView addSubview:switchBtn];
  30. self.youpaipswitchBtn = switchBtn;
  31. [switchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.right.offset(-14.0f);
  33. make.centerY.equalTo(self.contentView);
  34. make.size.mas_offset(CGSizeMake(40, 22));
  35. }];
  36. UILabel *titleL = [[UILabel alloc] init];
  37. titleL.font = LCFont(14.0f);
  38. titleL.textColor = LZ273145Color;
  39. [self.contentView addSubview:titleL];
  40. self.youpaiptitleL = titleL;
  41. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.left.offset(14.0f);
  43. make.bottom.equalTo(self.contentView.mas_centerY).offset(-3.0f);
  44. make.right.equalTo(switchBtn.mas_left).offset(-14.0f);
  45. }];
  46. UILabel *descL = [[UILabel alloc] init];
  47. descL.font = LCFont(12.0f);
  48. descL.textColor = LZA3AABEColor;
  49. descL.numberOfLines = 0;
  50. [self.contentView addSubview:descL];
  51. self.youpaipdescL = descL;
  52. [descL mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.left.offset(14.0f);
  54. make.top.equalTo(self.contentView.mas_centerY).offset(3.0f);
  55. make.right.equalTo(switchBtn.mas_left).offset(-14.0f);
  56. }];
  57. [self.contentView addLineWithColor:LZF5F4F7Color lineRect:CGRectMake(14.0f, 69.0f, KScreenWidth - 28.0f, 1.0f)];
  58. }
  59. - (void)youpaifreloadWithModel:(YOUPAILZVipSetterModel *)model{
  60. self.youpaipmodel = model;
  61. self.youpaiptitleL.text = model.youpaipname;
  62. self.youpaipdescL.text = model.youpaipdesc;
  63. self.youpaipswitchBtn.hidden = model.youpaipdisabled;
  64. self.youpaipswitchBtn.selected = model.youpaipstatus == 1;
  65. }
  66. - (void)youpaifswitchBtnClick:(UIButton *)sender{
  67. sender.selected = !sender.selected;
  68. self.youpaipmodel.youpaipstatus = sender.selected ? 1 : 2;
  69. if(self.switchBlock != nil){
  70. self.switchBlock(self.youpaipmodel);
  71. }
  72. }
  73. @end