XYPersonalCenterHeaderView.m 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. //
  2. // XYPersonalCenterHeaderView.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2019/12/21.
  6. // Copyright © 2019 翟玉磊. All rights reserved.
  7. //
  8. #import "XYPersonalCenterHeaderView.h"
  9. #import "XYPersonalCenterViewModel.h"
  10. #import "XYPersonalUserInfoView.h"
  11. #import "XYPersonalCenterHeaderItemView.h"
  12. #define itemCount 4
  13. @interface XYPersonalCenterHeaderView ()
  14. @property (nonatomic, readwrite, strong) XYPersonalUserInfoView *userInfoView;//90
  15. //@property (nonatomic, readwrite, strong) XYPersonalUserInfoView *userInfoView;10+74
  16. /// 会员信息
  17. @property (nonatomic, readwrite, strong) UIView *vipView;
  18. @property (nonatomic, readwrite, strong) UIImageView *vipBgImageView;
  19. @property (nonatomic, readwrite, strong) UIImageView *vipMarkImageView;
  20. @property (nonatomic, readwrite, strong) UILabel *vipLabel;
  21. @property (nonatomic, readwrite, strong) UIButton *vipButton;
  22. @property (nonatomic, readwrite, strong) NSMutableArray *views;
  23. @end
  24. @implementation XYPersonalCenterHeaderView
  25. #pragma mark - Public Method
  26. - (void)configureViewModel:(XYPersonalCenterViewModel *)viewModel {
  27. [self.userInfoView configureViewWithModel:viewModel.nowUser];
  28. // 会员信息
  29. self.vipMarkImageView.image = [XYLevelImageHander getVipImageWithLevel:viewModel.nowUser.vipLevel];
  30. self.vipLabel.text = [XYLevelImageHander getVipNameWithLevel:viewModel.nowUser.vipLevel];
  31. if ([XYUserInfoManager nowUser].vipLevel > 0 && StringIsNotEmpty([XYAppConfigModel getUrlVip])) {
  32. self.vipBgImageView.image = ImageNamed(@"icon_vip_bg");
  33. self.vipView.hidden = NO;
  34. }else {
  35. self.vipBgImageView.image = ImageNamed(@"icon_unvip_bg");
  36. self.vipView.hidden = YES;
  37. }
  38. for (NSInteger i = 0; i < self.views.count; i++) {
  39. XYPersonalCenterHeaderItemView *item = self.views[i];
  40. switch (i) {
  41. case 0:
  42. [item setupTitle:kLocalizedString(@"关注") content:[NSString stringWithFormat:@"%ld", (long)viewModel.followCount]];
  43. break;
  44. case 1:
  45. [item setupTitle:kLocalizedString(@"粉丝") content:[NSString stringWithFormat:@"%ld", (long)viewModel.fansCount]];
  46. break;
  47. case 2:
  48. [item setupTitle:kLocalizedString(@"足迹") content:[NSString stringWithFormat:@"%ld", viewModel.visitCount]];
  49. break;
  50. case 3:
  51. [item setupTitle:kLocalizedString(@"访客") content:[NSString stringWithFormat:@"%ld", viewModel.intervieweeCount]];
  52. item.visitFoot = YES;
  53. break;
  54. default:
  55. break;
  56. }
  57. }
  58. }
  59. #pragma mark - Private Method
  60. - (instancetype)initWithFrame:(CGRect)frame{
  61. if (self = [super initWithFrame:frame]) {
  62. // 初始化
  63. [self _setup];
  64. // 创建子控件
  65. [self _setupSubViews];
  66. // 布局子控件
  67. [self _makeSubViewsConstraints];
  68. }
  69. return self;
  70. }
  71. #pragma mark - 事件处理Or辅助方法
  72. - (void)vipButtonAction:(id)sender {
  73. if (self.delegate && [self.delegate respondsToSelector:@selector(vipAction)]) {
  74. [self.delegate vipAction];
  75. }
  76. }
  77. #pragma mark - Private Method
  78. - (void)_setup{
  79. self.views = [NSMutableArray new];
  80. [self addSubview:self.userInfoView];
  81. WeakSelf
  82. // 登录、查看个人信息
  83. [self.userInfoView setLoginAction:^{
  84. if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(loginAction)]) {
  85. [weakSelf.delegate loginAction];
  86. }
  87. }];
  88. }
  89. #pragma mark - 创建子控件
  90. - (void)_setupSubViews{
  91. [self addSubview:self.vipView];
  92. [self.vipView addSubview:self.vipBgImageView];
  93. [self.vipView addSubview:self.vipMarkImageView];
  94. [self.vipView addSubview:self.vipLabel];
  95. [self.vipView addSubview:self.vipButton];
  96. [self.vipButton addTarget:self action:@selector(vipButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  97. CGFloat width = (self.f_width-30) / itemCount;
  98. CGFloat y = self.userInfoView.bottom + 10;
  99. UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, y, self.f_width-30, 74.0f)];
  100. contentView.backgroundColor = Color_White;
  101. [self addSubview:contentView];
  102. kViewRadius(contentView, 16);
  103. for (NSInteger i = 0; i < itemCount; i++) {
  104. XYPersonalCenterHeaderItemView *item = [[XYPersonalCenterHeaderItemView alloc] initWithFrame:CGRectMake(width * i, 0, width, 74.0f)];
  105. item.lineView.image = ImageNamed(@"icon_anchor_head_line");
  106. item.tag = i;
  107. switch (i) {
  108. case 0:
  109. [item setupTitle:kLocalizedString(@"关注") content:@"0"];
  110. break;
  111. case 1:
  112. [item setupTitle:kLocalizedString(@"粉丝") content:@"0"];
  113. break;
  114. case 2:
  115. [item setupTitle:kLocalizedString(@"足迹") content:@"0"];
  116. break;
  117. case 3:
  118. [item setupTitle:kLocalizedString(@"访客") content:@"0"];
  119. item.lineView.hidden = YES;
  120. break;
  121. default:
  122. break;
  123. }
  124. [contentView addSubview:item];
  125. WeakSelf
  126. [item setItemClickActionBlock:^(NSInteger index) {
  127. if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(didSelectClickItemWithIndex:)]) {
  128. [weakSelf.delegate didSelectClickItemWithIndex:index];
  129. }
  130. }];
  131. [self.views addObject:item];
  132. }
  133. }
  134. #pragma mark - 布局子控件
  135. - (void)_makeSubViewsConstraints{
  136. [self.vipView mas_makeConstraints:^(MASConstraintMaker *make) {
  137. make.right.top.equalTo(self);
  138. make.width.equalTo(@121.0f);
  139. make.height.equalTo(@27.0f);
  140. }];
  141. [self.vipBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  142. make.edges.equalTo(self.vipView);
  143. }];
  144. [self.vipMarkImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  145. make.left.equalTo(self.vipView).offset(36.0f);
  146. make.centerY.equalTo(self.vipView);
  147. make.width.height.equalTo(@20.0f);
  148. }];
  149. [self.vipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  150. make.left.equalTo(self.vipMarkImageView.mas_right).offset(3.0f);
  151. make.centerY.equalTo(self.vipView);
  152. make.right.equalTo(self.vipView).offset(-10.0f);
  153. }];
  154. [self.vipButton mas_makeConstraints:^(MASConstraintMaker *make) {
  155. make.edges.equalTo(self.vipView);
  156. }];
  157. }
  158. - (XYPersonalUserInfoView *)userInfoView {
  159. if (!_userInfoView) {
  160. _userInfoView = [[XYPersonalUserInfoView alloc] initWithFrame:CGRectMake(0, 0.0f, self.f_width, 90)];
  161. [_userInfoView configureViewWithModel:[XYUserInfoManager nowUser]];
  162. _userInfoView.backgroundColor = [UIColor clearColor];
  163. }
  164. return _userInfoView;
  165. }
  166. - (UIView *)vipView {
  167. if (!_vipView) {
  168. _vipView = [UIView new];
  169. }
  170. return _vipView;
  171. }
  172. - (UIImageView *)vipBgImageView {
  173. if (!_vipBgImageView) {
  174. _vipBgImageView = [UIImageView new];
  175. _vipBgImageView.image = ImageNamed(@"icon_vip_bg");
  176. }
  177. return _vipBgImageView;
  178. }
  179. - (UIImageView *)vipMarkImageView {
  180. if (!_vipMarkImageView) {
  181. _vipMarkImageView = [UIImageView new];
  182. }
  183. return _vipMarkImageView;
  184. }
  185. - (UILabel *)vipLabel {
  186. if (!_vipLabel) {
  187. _vipLabel = [UILabel createLabelTextColor:Color_White fount:Font_B(12)];
  188. _vipLabel.textAlignment = NSTextAlignmentCenter;
  189. }
  190. return _vipLabel;
  191. }
  192. - (UIButton *)vipButton {
  193. if (!_vipButton) {
  194. _vipButton = [UIButton buttonWithType:UIButtonTypeCustom];
  195. }
  196. return _vipButton;
  197. }
  198. @end