YMMineWealthView.m 9.1 KB

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