// // YMAccountBalanceInfoView.m // MSYOUPAI // // Created by YoMi on 2024/2/28. // Copyright © 2024 MS. All rights reserved. // #import "YMAccountBalanceInfoView.h" #import "YMAccountBalanceViewModel.h" @interface YMAccountBalanceInfoView () /// 账户余额VM @property (nonatomic, strong) YMAccountBalanceViewModel *viewModel; /// 信息背景图 @property (nonatomic, strong) UIImageView *infoBgView; /// 用户余额图标 @property (nonatomic, strong) UIImageView *userBalanceIcon; /// 用户剩余余额标签 @property (nonatomic, strong) UILabel *userRemainingBalanceLb; /// 用户余额名称标签 @property (nonatomic, strong) UILabel *userBalanceNameLb; /// 收支明细按钮 @property (nonatomic, strong) UIButton *incomeBreakdownBtn; @end @implementation YMAccountBalanceInfoView - (void)ym_setupViews{ self.backgroundColor = UIColor.clearColor; [self addSubview:self.infoBgView]; [self addSubview:self.userBalanceIcon]; [self addSubview:self.userBalanceNameLb]; [self addSubview:self.userRemainingBalanceLb]; [self addSubview:self.incomeBreakdownBtn]; [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; } - (void)updateConstraints{ [self.infoBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self).offset(12); make.left.equalTo(self).offset(12); make.right.equalTo(self).offset(-12); make.bottom.equalTo(self); make.height.mas_equalTo(adapt(102)); }]; [self.userBalanceIcon mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.infoBgView).offset(adapt(0)); make.left.equalTo(self.infoBgView.mas_left).offset(adapt(18)); make.width.mas_equalTo(adapt(46)); make.height.mas_equalTo(adapt(46)); }]; [self.userBalanceNameLb mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.userBalanceIcon.mas_centerY).offset(adapt(-5)); make.left.equalTo(self.userBalanceIcon.mas_right).offset(adapt(8)); }]; [self.userRemainingBalanceLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.userBalanceIcon.mas_centerY).offset(adapt(0)); make.left.equalTo(self.userBalanceIcon.mas_right).offset(adapt(8)); }]; [self.incomeBreakdownBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.infoBgView).offset(0); make.right.equalTo(self.infoBgView).offset(adapt(-20)); make.width.mas_equalTo(adapt(88)); make.height.mas_equalTo(adapt(30)); }]; [super updateConstraints]; } - (void)ym_bindViewModel:(YMAccountBalanceViewModel *)viewModel{ if (!viewModel) { return; } _viewModel = viewModel; RAC(self.userRemainingBalanceLb, text) = RACObserve(self.viewModel, userRemainingBalance); } - (UIImageView *)infoBgView{ if (!_infoBgView) { _infoBgView = [[UIImageView alloc]init]; _infoBgView.image = ImageByName(@"ym_account_balance_bg_icon"); // _infoBgView.layer.cornerRadius = adapt(10); // _infoBgView.layer.masksToBounds = YES; // _infoBgView.clipsToBounds = YES; } return _infoBgView; } - (UIImageView *)userBalanceIcon{ if (!_userBalanceIcon) { _userBalanceIcon = [[UIImageView alloc]init]; _userBalanceIcon.image = ImageByName(@"ym_account_balance_diamond_icon"); } return _userBalanceIcon; } - (UILabel *)userRemainingBalanceLb{ if (!_userRemainingBalanceLb) { _userRemainingBalanceLb = [[UILabel alloc]init]; _userRemainingBalanceLb.font = LCBoldFont(24); _userRemainingBalanceLb.textColor = HexColorFromRGB(0x333333); _userRemainingBalanceLb.textAlignment = NSTextAlignmentLeft; _userRemainingBalanceLb.text = @"******"; } return _userRemainingBalanceLb; } - (UIButton *)incomeBreakdownBtn { if (!_incomeBreakdownBtn) { _incomeBreakdownBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _incomeBreakdownBtn.titleLabel.font = LCFont(13); [_incomeBreakdownBtn setTitle:@"收支明细 " forState:UIControlStateNormal]; [_incomeBreakdownBtn setImage:ImageByName(@"ym_account_balance_go_detail") forState:(UIControlStateNormal)]; _incomeBreakdownBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft; [_incomeBreakdownBtn setTitleColor:HexColorFromRGB(0x000000) forState:UIControlStateNormal]; _incomeBreakdownBtn.backgroundColor = HexColorFromRGB(0xF6F6F6); _incomeBreakdownBtn.layer.cornerRadius = adapt(15); _incomeBreakdownBtn.layer.masksToBounds = YES; WS(weakSelf) [[[_incomeBreakdownBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { [weakSelf.viewModel gotoIncomeBreakdown]; }]; } return _incomeBreakdownBtn; } - (UILabel *)userBalanceNameLb{ if (!_userBalanceNameLb) { _userBalanceNameLb = [[UILabel alloc]init]; _userBalanceNameLb.font = LCFont(12); _userBalanceNameLb.textColor = HexColorFromRGB(0x333333); _userBalanceNameLb.textAlignment = NSTextAlignmentLeft; _userBalanceNameLb.text = @"钻石余额"; } return _userBalanceNameLb; } @end