YMAccountBalanceInfoView.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // YMAccountBalanceInfoView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/28.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMAccountBalanceInfoView.h"
  9. #import "YMAccountBalanceViewModel.h"
  10. @interface YMAccountBalanceInfoView ()
  11. /// 账户余额VM
  12. @property (nonatomic, strong) YMAccountBalanceViewModel *viewModel;
  13. /// 信息背景图
  14. @property (nonatomic, strong) UIImageView *infoBgView;
  15. /// 用户余额图标
  16. @property (nonatomic, strong) UIImageView *userBalanceIcon;
  17. /// 用户剩余余额标签
  18. @property (nonatomic, strong) UILabel *userRemainingBalanceLb;
  19. /// 用户余额名称标签
  20. @property (nonatomic, strong) UILabel *userBalanceNameLb;
  21. /// 收支明细按钮
  22. @property (nonatomic, strong) UIButton *incomeBreakdownBtn;
  23. @end
  24. @implementation YMAccountBalanceInfoView
  25. - (void)ym_setupViews{
  26. self.backgroundColor = UIColor.clearColor;
  27. [self addSubview:self.infoBgView];
  28. [self addSubview:self.userBalanceIcon];
  29. [self addSubview:self.userBalanceNameLb];
  30. [self addSubview:self.userRemainingBalanceLb];
  31. [self addSubview:self.incomeBreakdownBtn];
  32. [self setNeedsUpdateConstraints];
  33. [self updateConstraintsIfNeeded];
  34. }
  35. - (void)updateConstraints{
  36. [self.infoBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.top.equalTo(self).offset(12);
  38. make.left.equalTo(self).offset(12);
  39. make.right.equalTo(self).offset(-12);
  40. make.bottom.equalTo(self);
  41. make.height.mas_equalTo(adapt(102));
  42. }];
  43. [self.userBalanceIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.centerY.equalTo(self.infoBgView).offset(adapt(0));
  45. make.left.equalTo(self.infoBgView.mas_left).offset(adapt(18));
  46. make.width.mas_equalTo(adapt(46));
  47. make.height.mas_equalTo(adapt(46));
  48. }];
  49. [self.userBalanceNameLb mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.bottom.equalTo(self.userBalanceIcon.mas_centerY).offset(adapt(-5));
  51. make.left.equalTo(self.userBalanceIcon.mas_right).offset(adapt(8));
  52. }];
  53. [self.userRemainingBalanceLb mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.top.equalTo(self.userBalanceIcon.mas_centerY).offset(adapt(0));
  55. make.left.equalTo(self.userBalanceIcon.mas_right).offset(adapt(8));
  56. }];
  57. [self.incomeBreakdownBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.centerY.equalTo(self.infoBgView).offset(0);
  59. make.right.equalTo(self.infoBgView).offset(adapt(-20));
  60. make.width.mas_equalTo(adapt(88));
  61. make.height.mas_equalTo(adapt(30));
  62. }];
  63. [super updateConstraints];
  64. }
  65. - (void)ym_bindViewModel:(YMAccountBalanceViewModel *)viewModel{
  66. if (!viewModel) {
  67. return;
  68. }
  69. _viewModel = viewModel;
  70. RAC(self.userRemainingBalanceLb, text) = RACObserve(self.viewModel, userRemainingBalance);
  71. }
  72. - (UIImageView *)infoBgView{
  73. if (!_infoBgView) {
  74. _infoBgView = [[UIImageView alloc]init];
  75. _infoBgView.image = ImageByName(@"ym_account_balance_bg_icon");
  76. // _infoBgView.layer.cornerRadius = adapt(10);
  77. // _infoBgView.layer.masksToBounds = YES;
  78. // _infoBgView.clipsToBounds = YES;
  79. }
  80. return _infoBgView;
  81. }
  82. - (UIImageView *)userBalanceIcon{
  83. if (!_userBalanceIcon) {
  84. _userBalanceIcon = [[UIImageView alloc]init];
  85. _userBalanceIcon.image = ImageByName(@"ym_account_balance_diamond_icon");
  86. }
  87. return _userBalanceIcon;
  88. }
  89. - (UILabel *)userRemainingBalanceLb{
  90. if (!_userRemainingBalanceLb) {
  91. _userRemainingBalanceLb = [[UILabel alloc]init];
  92. _userRemainingBalanceLb.font = LCBoldFont(24);
  93. _userRemainingBalanceLb.textColor = HexColorFromRGB(0x333333);
  94. _userRemainingBalanceLb.textAlignment = NSTextAlignmentLeft;
  95. _userRemainingBalanceLb.text = @"******";
  96. }
  97. return _userRemainingBalanceLb;
  98. }
  99. - (UIButton *)incomeBreakdownBtn {
  100. if (!_incomeBreakdownBtn) {
  101. _incomeBreakdownBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  102. _incomeBreakdownBtn.titleLabel.font = LCFont(13);
  103. [_incomeBreakdownBtn setTitle:@"收支明细 " forState:UIControlStateNormal];
  104. [_incomeBreakdownBtn setImage:ImageByName(@"ym_account_balance_go_detail") forState:(UIControlStateNormal)];
  105. _incomeBreakdownBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
  106. [_incomeBreakdownBtn setTitleColor:HexColorFromRGB(0x000000) forState:UIControlStateNormal];
  107. _incomeBreakdownBtn.backgroundColor = HexColorFromRGB(0xF6F6F6);
  108. _incomeBreakdownBtn.layer.cornerRadius = adapt(15);
  109. _incomeBreakdownBtn.layer.masksToBounds = YES;
  110. WS(weakSelf)
  111. [[[_incomeBreakdownBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  112. [weakSelf.viewModel gotoIncomeBreakdown];
  113. }];
  114. }
  115. return _incomeBreakdownBtn;
  116. }
  117. - (UILabel *)userBalanceNameLb{
  118. if (!_userBalanceNameLb) {
  119. _userBalanceNameLb = [[UILabel alloc]init];
  120. _userBalanceNameLb.font = LCFont(12);
  121. _userBalanceNameLb.textColor = HexColorFromRGB(0x333333);
  122. _userBalanceNameLb.textAlignment = NSTextAlignmentLeft;
  123. _userBalanceNameLb.text = @"钻石余额";
  124. }
  125. return _userBalanceNameLb;
  126. }
  127. @end