YMMineWealthView.m 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //
  2. // YMMineWealthView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/15.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMMineWealthView.h"
  9. #import "YMMineViewModel.h"
  10. @interface YMMineWealthView ()
  11. /// 我的VM
  12. @property (nonatomic, strong) YMMineViewModel *viewModel;
  13. /// 我的余额视图
  14. @property (nonatomic, strong) UIView *myBalanceView;
  15. /// 我的余额图标
  16. @property (nonatomic, strong) UIImageView *myBalanceIcon;
  17. /// 我的余额内容标签
  18. @property (nonatomic, strong) UILabel *myBalanceContentLb;
  19. /// 我的余额标题标签
  20. @property (nonatomic, strong) UILabel *myBalanceTitleLb;
  21. /// 我的收益视图
  22. @property (nonatomic, strong) UIView *myEarningsView;
  23. /// 我的收益图标
  24. @property (nonatomic, strong) UIImageView *myEarningsIcon;
  25. /// 我的收益内容标签
  26. @property (nonatomic, strong) UILabel *myEarningsContentLb;
  27. /// 我的收益标题标签
  28. @property (nonatomic, strong) UILabel *myEarningsTitleLb;
  29. @end
  30. @implementation YMMineWealthView
  31. - (void)ym_setupViews{
  32. [self addSubview:self.myBalanceView];
  33. [self.myBalanceView addSubview:self.myBalanceIcon];
  34. [self.myBalanceView addSubview:self.myBalanceContentLb];
  35. [self.myBalanceView addSubview:self.myBalanceTitleLb];
  36. [self addSubview:self.myEarningsView];
  37. [self.myEarningsView addSubview:self.myEarningsIcon];
  38. [self.myEarningsView addSubview:self.myEarningsContentLb];
  39. [self.myEarningsView addSubview:self.myEarningsTitleLb];
  40. [self setNeedsUpdateConstraints];
  41. [self updateConstraintsIfNeeded];
  42. }
  43. - (void)updateConstraints{
  44. NSArray *btnArr = @[self.myBalanceView,self.myEarningsView];
  45. // 实现masonry水平固定控件宽度方法
  46. // axisType 横排还是竖排
  47. // fixedSpacing 两个控件间隔
  48. // leadSpacing 第一个控件与边缘的间隔
  49. // tailSpacing 最后一个控件与边缘的间隔
  50. [btnArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:adapt(20) leadSpacing:adapt(15) tailSpacing:adapt(15)];
  51. // 设置array的垂直方向的约束
  52. [btnArr mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.top.equalTo(self).offset(adapt(10));
  54. make.bottom.equalTo(self).offset(adapt(-10));
  55. make.height.mas_equalTo(adapt(64));
  56. }];
  57. [self.myBalanceIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.centerY.equalTo(self.myBalanceView.mas_centerY);
  59. make.left.equalTo(self.myBalanceView).offset(adapt(11));
  60. make.width.height.mas_equalTo(adapt(44));
  61. }];
  62. [self.myBalanceContentLb mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.top.equalTo(self.myBalanceIcon.mas_top);
  64. make.left.equalTo(self.myBalanceIcon.mas_right).offset(8);
  65. make.right.equalTo(self.myBalanceView).offset(adapt(-5));
  66. }];
  67. [self.myBalanceTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.top.equalTo(self.myBalanceContentLb.mas_bottom).offset(adapt(3));
  69. make.left.equalTo(self.myBalanceIcon.mas_right).offset(8);
  70. }];
  71. [self.myEarningsIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.centerY.equalTo(self.myEarningsView.mas_centerY);
  73. make.left.equalTo(self.myEarningsView).offset(adapt(5));
  74. make.width.height.mas_equalTo(adapt(44));
  75. }];
  76. [self.myEarningsContentLb mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.top.equalTo(self.myEarningsIcon.mas_top);
  78. make.left.equalTo(self.myEarningsIcon.mas_right).offset(8);
  79. make.right.equalTo(self.myEarningsView).offset(adapt(-5));
  80. }];
  81. [self.myEarningsTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.top.equalTo(self.myEarningsContentLb.mas_bottom).offset(adapt(3));
  83. make.left.equalTo(self.myEarningsIcon.mas_right).offset(8);
  84. }];
  85. [super updateConstraints];
  86. }
  87. - (void)ym_bindViewModel:(YMMineViewModel *)viewModel{
  88. if (!viewModel) {
  89. return;
  90. }
  91. _viewModel = viewModel;
  92. RAC(self.myBalanceContentLb, text) = RACObserve(self.viewModel, userBalance);
  93. RAC(self.myEarningsContentLb, text) = RACObserve(self.viewModel, userEarnings);
  94. }
  95. - (UIView *)myBalanceView{
  96. if (!_myBalanceView) {
  97. _myBalanceView = [[UIView alloc]init];
  98. _myBalanceView.backgroundColor = HexColorFromRGB(0xFFF8F0);
  99. _myBalanceView.layer.cornerRadius = adapt(8);
  100. _myBalanceView.layer.masksToBounds = YES;
  101. _myBalanceView.userInteractionEnabled = YES;
  102. [_myBalanceView ym_setGradientBackgroundWithColors:@[HexColorFromRGB(0xFDDEF2),HexColorFromRGB(0xFFF6FC),HexColorFromRGB(0xFFD6F2),] locations:@[@0, @0.5, @1] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
  103. WS(weakSelf)
  104. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
  105. [_myBalanceView addGestureRecognizer:tap];
  106. [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  107. [weakSelf.viewModel gotoAccountBalance];
  108. }];
  109. }
  110. return _myBalanceView;
  111. }
  112. - (UIImageView *)myBalanceIcon{
  113. if (!_myBalanceIcon) {
  114. _myBalanceIcon = [[UIImageView alloc]init];
  115. _myBalanceIcon.image = ImageByName(@"ym_mine_diamond_icon");
  116. }
  117. return _myBalanceIcon;
  118. }
  119. - (UILabel *)myBalanceContentLb{
  120. if (!_myBalanceContentLb) {
  121. _myBalanceContentLb = [[UILabel alloc]init];
  122. _myBalanceContentLb.font = LCBoldFont(21);
  123. _myBalanceContentLb.textColor = HexColorFromRGB(0x292929);
  124. _myBalanceContentLb.textAlignment = NSTextAlignmentLeft;
  125. _myBalanceContentLb.text = @"0";
  126. }
  127. return _myBalanceContentLb;
  128. }
  129. - (UILabel *)myBalanceTitleLb{
  130. if (!_myBalanceTitleLb) {
  131. _myBalanceTitleLb = [[UILabel alloc]init];
  132. _myBalanceTitleLb.font = LCFont(11);
  133. _myBalanceTitleLb.textColor = HexColorFromRGBA(0x000000,0.45);
  134. _myBalanceTitleLb.textAlignment = NSTextAlignmentLeft;
  135. _myBalanceTitleLb.text = @"我的余额";
  136. }
  137. return _myBalanceTitleLb;
  138. }
  139. - (UIView *)myEarningsView{
  140. if (!_myEarningsView) {
  141. _myEarningsView = [[UIView alloc]init];
  142. _myEarningsView.backgroundColor = HexColorFromRGB(0xF2FAFF);
  143. _myEarningsView.layer.cornerRadius = adapt(8);
  144. _myEarningsView.layer.masksToBounds = YES;
  145. _myEarningsView.userInteractionEnabled = YES;
  146. [_myEarningsView ym_setGradientBackgroundWithColors:@[HexColorFromRGB(0xEAD7FE),HexColorFromRGB(0xF9F6FF),HexColorFromRGB(0xEAD7FE),] locations:@[@0, @0.5, @1] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
  147. WS(weakSelf)
  148. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
  149. [_myEarningsView addGestureRecognizer:tap];
  150. [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  151. [weakSelf.viewModel gotoMyEarnings];
  152. }];
  153. }
  154. return _myEarningsView;
  155. }
  156. - (UIImageView *)myEarningsIcon{
  157. if (!_myEarningsIcon) {
  158. _myEarningsIcon = [[UIImageView alloc]init];
  159. _myEarningsIcon.image = ImageByName(@"ym_mine_coin_icon");
  160. }
  161. return _myEarningsIcon;
  162. }
  163. - (UILabel *)myEarningsContentLb{
  164. if (!_myEarningsContentLb) {
  165. _myEarningsContentLb = [[UILabel alloc]init];
  166. _myEarningsContentLb.font = LCBoldFont(17);
  167. _myEarningsContentLb.textColor = HexColorFromRGB(0x292929);
  168. _myEarningsContentLb.textAlignment = NSTextAlignmentLeft;
  169. _myEarningsContentLb.text = @"0";
  170. }
  171. return _myEarningsContentLb;
  172. }
  173. - (UILabel *)myEarningsTitleLb{
  174. if (!_myEarningsTitleLb) {
  175. _myEarningsTitleLb = [[UILabel alloc]init];
  176. _myEarningsTitleLb.font = LCFont(11);
  177. _myEarningsTitleLb.textColor = HexColorFromRGBA(0x000000,0.45);
  178. _myEarningsTitleLb.textAlignment = NSTextAlignmentLeft;
  179. _myEarningsTitleLb.text = @"我的收益";
  180. }
  181. return _myEarningsTitleLb;
  182. }
  183. @end