YMMemberInfoView.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //
  2. // YMMemberInfoView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/27.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMMemberInfoView.h"
  9. #import "YMMemberCenterViewModel.h"
  10. @interface YMMemberInfoView ()
  11. /// 会员中心VM
  12. @property (nonatomic, strong) YMMemberCenterViewModel *viewModel;
  13. /// 信息背景图
  14. @property (nonatomic, strong) UIImageView *infoBgView;
  15. @property (nonatomic, strong) UIImageView *hgBgView;
  16. /// 用户头像视图
  17. @property (nonatomic, strong) UIImageView *userAvatarView;
  18. /// 用户昵称标签
  19. @property (nonatomic, strong) UILabel *userNicknameLb;
  20. /// 有效日期标签
  21. @property (nonatomic, strong) UILabel *validityDateLb;
  22. /// 提示视图
  23. @property (nonatomic, strong) UIView *tipsView;
  24. /// 提示标签
  25. @property (nonatomic, strong) UILabel *tipsLb;
  26. @end
  27. @implementation YMMemberInfoView
  28. - (void)ym_setupViews{
  29. [self addSubview:self.infoBgView];
  30. [self.infoBgView addSubview:self.hgBgView];
  31. [self.infoBgView addSubview:self.userAvatarView];
  32. [self.infoBgView addSubview:self.userNicknameLb];
  33. [self.infoBgView addSubview:self.validityDateLb];
  34. [self.infoBgView addSubview:self.tipsView];
  35. [self.tipsView addSubview:self.tipsLb];
  36. [self setNeedsUpdateConstraints];
  37. [self updateConstraintsIfNeeded];
  38. }
  39. - (void)updateConstraints{
  40. [self.infoBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.top.equalTo(self);
  42. make.left.equalTo(self);
  43. make.right.equalTo(self);
  44. make.bottom.equalTo(self);
  45. make.height.mas_equalTo(adapt(98));
  46. }];
  47. [self.hgBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.top.equalTo(self.infoBgView).offset(adapt(4));
  49. make.right.equalTo(self.infoBgView).offset(adapt(-10));
  50. make.width.mas_equalTo(adapt(104));
  51. make.height.mas_equalTo(adapt(68));
  52. }];
  53. [self.userAvatarView mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.top.equalTo(self.infoBgView).offset(adapt(7));
  55. make.left.equalTo(self.infoBgView).offset(adapt(12));
  56. make.width.height.mas_equalTo(adapt(58));
  57. }];
  58. [self.userNicknameLb mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.bottom.equalTo(self.userAvatarView.mas_centerY).offset(adapt(-5));
  60. make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(12));
  61. }];
  62. [self.validityDateLb mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.top.equalTo(self.userNicknameLb.mas_bottom).offset(5);
  64. make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(12));
  65. }];
  66. [self.tipsView mas_makeConstraints:^(MASConstraintMaker *make) {
  67. make.bottom.equalTo(self.infoBgView).offset(0);
  68. make.left.equalTo(self.infoBgView);
  69. make.right.equalTo(self.infoBgView);
  70. make.height.mas_equalTo(adapt(25));
  71. }];
  72. [self.tipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.centerY.equalTo(self.tipsView.mas_centerY);
  74. make.left.equalTo(self.tipsView).offset(adapt(17));
  75. make.right.equalTo(self.tipsView).offset(adapt(-17));
  76. }];
  77. [super updateConstraints];
  78. }
  79. - (void)ym_bindViewModel:(YMMemberCenterViewModel *)viewModel{
  80. if (!viewModel) {
  81. return;
  82. }
  83. _viewModel = viewModel;
  84. @weakify(self)
  85. [[[[RACObserve(self.viewModel, userAvatar) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * userAvatar) {
  86. @strongify(self)
  87. [self.userAvatarView sd_setImageWithURL:[LCTools getImageUrlWithAddress:userAvatar]];
  88. }];
  89. RAC(self.userNicknameLb, text) = RACObserve(self.viewModel, userNickname);
  90. RAC(self.validityDateLb, text) = RACObserve(self.viewModel, validityDate);
  91. }
  92. - (UIImageView *)infoBgView{
  93. if (!_infoBgView) {
  94. _infoBgView = [[UIImageView alloc]init];
  95. //_infoBgView.image = ImageByName(@"ym_member_center_info_bg_icon");
  96. _infoBgView.layer.cornerRadius = adapt(10);
  97. _infoBgView.layer.masksToBounds = YES;
  98. _infoBgView.clipsToBounds = YES;
  99. }
  100. return _infoBgView;
  101. }
  102. - (UIImageView *)hgBgView{
  103. if (!_hgBgView) {
  104. _hgBgView = [[UIImageView alloc]init];
  105. _hgBgView.hidden = YES;
  106. _hgBgView.image = ImageByName(@"ym_member_center_huangguan");
  107. }
  108. return _hgBgView;
  109. }
  110. - (UIImageView *)userAvatarView{
  111. if (!_userAvatarView) {
  112. _userAvatarView = [[UIImageView alloc]init];
  113. _userAvatarView.backgroundColor = UIColor.lightGrayColor;
  114. _userAvatarView.layer.borderColor = UIColor.whiteColor.CGColor;
  115. _userAvatarView.layer.borderWidth = adapt(2);
  116. _userAvatarView.layer.cornerRadius = adapt(58)/2;
  117. _userAvatarView.layer.masksToBounds = YES;
  118. }
  119. return _userAvatarView;
  120. }
  121. - (UILabel *)userNicknameLb{
  122. if (!_userNicknameLb) {
  123. _userNicknameLb = [[UILabel alloc]init];
  124. _userNicknameLb.font = LCBoldFont(16);
  125. _userNicknameLb.textColor = rgba(99, 50, 40, 1);
  126. _userNicknameLb.textAlignment = NSTextAlignmentLeft;
  127. _userNicknameLb.text = @"******";
  128. }
  129. return _userNicknameLb;
  130. }
  131. - (UILabel *)validityDateLb{
  132. if (!_validityDateLb) {
  133. _validityDateLb = [[UILabel alloc]init];
  134. _validityDateLb.font = LCFont(11);
  135. _validityDateLb.textColor = rgba(99, 50, 40, 1);
  136. _validityDateLb.textAlignment = NSTextAlignmentLeft;
  137. _validityDateLb.text = @"******";
  138. }
  139. return _validityDateLb;
  140. }
  141. - (UIView *)tipsView{
  142. if (!_tipsView) {
  143. _tipsView = [[UIView alloc]init];
  144. _tipsView.backgroundColor = UIColor.clearColor;
  145. // [_tipsView ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
  146. }
  147. return _tipsView;
  148. }
  149. - (UILabel *)tipsLb{
  150. if (!_tipsLb) {
  151. _tipsLb = [[UILabel alloc]init];
  152. _tipsLb.hidden = YES;
  153. _tipsLb.font = LCFont(12);
  154. _tipsLb.textColor = HexColorFromRGB(0x834A00);
  155. _tipsLb.textAlignment = NSTextAlignmentLeft;
  156. _tipsLb.text = @"9大特权,提升个性化体验";
  157. }
  158. return _tipsLb;
  159. }
  160. @end