YMChatNotificationCell.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // YMChatNotificationCell.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/21.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMChatNotificationCell.h"
  9. #import "YMChatNotificationCellViewModel.h"
  10. @interface YMChatNotificationCell ()
  11. /// 消息通知-行VM
  12. @property (nonatomic, strong) YMChatNotificationCellViewModel *viewModel;
  13. /// 功能标签
  14. @property (nonatomic, strong) UILabel *functionsLb;
  15. /// 开关按钮
  16. @property (nonatomic, strong) UIButton *switchBtn;
  17. @end
  18. @implementation YMChatNotificationCell
  19. - (void)awakeFromNib {
  20. [super awakeFromNib];
  21. // Initialization code
  22. }
  23. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  24. [super setSelected:selected animated:animated];
  25. // Configure the view for the selected state
  26. }
  27. - (void)ym_setupViews{
  28. [self.contentView addSubview:self.functionsLb];
  29. [self.contentView addSubview:self.switchBtn];
  30. [self setNeedsUpdateConstraints];
  31. [self updateConstraintsIfNeeded];
  32. }
  33. - (void)updateConstraints{
  34. [self.functionsLb mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.centerY.equalTo(self.contentView.mas_centerY);
  36. make.left.equalTo(self.contentView).offset(adapt(15));
  37. }];
  38. [self.switchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.centerY.equalTo(self.contentView.mas_centerY);
  40. make.right.equalTo(self.contentView).offset(adapt(-15));
  41. make.width.mas_equalTo(adapt(36));
  42. make.height.mas_equalTo(adapt(20));
  43. }];
  44. [super updateConstraints];
  45. }
  46. - (void)ym_bindViewModel:(YMChatNotificationCellViewModel *)viewModel{
  47. if (!viewModel) {
  48. return;
  49. }
  50. _viewModel = viewModel;
  51. self.functionsLb.text = self.viewModel.rowTitle;
  52. if (self.viewModel.isOpen) {
  53. [self.switchBtn setImage:ImageByName(@"ym_mine_switch_selected_icon") forState:UIControlStateNormal];
  54. } else {
  55. [self.switchBtn setImage:ImageByName(@"ym_mine_switch_normal_icon") forState:UIControlStateNormal];
  56. }
  57. }
  58. - (UILabel *)functionsLb{
  59. if (!_functionsLb) {
  60. _functionsLb = [[UILabel alloc]init];
  61. _functionsLb.font = LCFont(15);
  62. _functionsLb.textColor = HexColorFromRGB(0x171A1D);
  63. _functionsLb.textAlignment = NSTextAlignmentLeft;
  64. _functionsLb.text = @"******";
  65. }
  66. return _functionsLb;
  67. }
  68. - (UIButton *)switchBtn{
  69. if (!_switchBtn) {
  70. _switchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  71. [_switchBtn setImage:ImageByName(@"ym_mine_switch_normal_icon") forState:UIControlStateNormal];
  72. WS(weakSelf)
  73. [[[_switchBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  74. if (weakSelf.viewModel.switchNotificationBlock) {
  75. weakSelf.viewModel.switchNotificationBlock();
  76. }
  77. }];
  78. }
  79. return _switchBtn;
  80. }
  81. @end