123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- //
- // YMChatNotificationCell.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/21.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMChatNotificationCell.h"
- #import "YMChatNotificationCellViewModel.h"
- @interface YMChatNotificationCell ()
- /// 消息通知-行VM
- @property (nonatomic, strong) YMChatNotificationCellViewModel *viewModel;
- /// 功能标签
- @property (nonatomic, strong) UILabel *functionsLb;
- /// 开关按钮
- @property (nonatomic, strong) UIButton *switchBtn;
- @end
- @implementation YMChatNotificationCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (void)ym_setupViews{
- [self.contentView addSubview:self.functionsLb];
- [self.contentView addSubview:self.switchBtn];
- [self setNeedsUpdateConstraints];
- [self updateConstraintsIfNeeded];
- }
- - (void)updateConstraints{
-
- [self.functionsLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.contentView.mas_centerY);
- make.left.equalTo(self.contentView).offset(adapt(15));
- }];
-
- [self.switchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.contentView.mas_centerY);
- make.right.equalTo(self.contentView).offset(adapt(-15));
- make.width.mas_equalTo(adapt(36));
- make.height.mas_equalTo(adapt(20));
- }];
-
- [super updateConstraints];
- }
- - (void)ym_bindViewModel:(YMChatNotificationCellViewModel *)viewModel{
- if (!viewModel) {
- return;
- }
-
- _viewModel = viewModel;
-
- self.functionsLb.text = self.viewModel.rowTitle;
- if (self.viewModel.isOpen) {
- [self.switchBtn setImage:ImageByName(@"ym_mine_switch_selected_icon") forState:UIControlStateNormal];
- } else {
- [self.switchBtn setImage:ImageByName(@"ym_mine_switch_normal_icon") forState:UIControlStateNormal];
- }
- }
- - (UILabel *)functionsLb{
- if (!_functionsLb) {
- _functionsLb = [[UILabel alloc]init];
- _functionsLb.font = LCFont(15);
- _functionsLb.textColor = HexColorFromRGB(0x171A1D);
- _functionsLb.textAlignment = NSTextAlignmentLeft;
- _functionsLb.text = @"******";
- }
- return _functionsLb;
- }
- - (UIButton *)switchBtn{
- if (!_switchBtn) {
- _switchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_switchBtn setImage:ImageByName(@"ym_mine_switch_normal_icon") forState:UIControlStateNormal];
- WS(weakSelf)
- [[[_switchBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
- if (weakSelf.viewModel.switchNotificationBlock) {
- weakSelf.viewModel.switchNotificationBlock();
- }
- }];
- }
- return _switchBtn;
- }
- @end
|