YMRankingListCell.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // YMRankingListCell.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/14.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMRankingListCell.h"
  9. #import "YMRankingListCellViewModel.h"
  10. @interface YMRankingListCell()
  11. /// ViewModel
  12. @property (nonatomic, strong) YMRankingListCellViewModel *viewModel;
  13. /// 基础视图
  14. @property (nonatomic, strong) UIView *baseView;
  15. /// 用户排名标签
  16. @property (nonatomic, strong) UILabel *userRankingNoLb;
  17. /// 用户头像视图
  18. @property (nonatomic, strong) UIImageView *userAvatarView;
  19. /// 用户昵称标签
  20. @property (nonatomic, strong) UILabel *userNicknameLb;
  21. /// 用户排名差异标签
  22. @property (nonatomic, strong) UILabel *userRankingDifferenceLb;
  23. /// 在线状态视图
  24. @property (nonatomic, strong) UIImageView *onlineStatusView;
  25. @end
  26. @implementation YMRankingListCell
  27. - (void)ym_setupViews{
  28. self.backgroundColor = UIColor.clearColor;
  29. self.contentView.backgroundColor = UIColor.clearColor;
  30. [self.contentView addSubview:self.baseView];
  31. [self.baseView addSubview:self.userRankingNoLb];
  32. [self.baseView addSubview:self.userAvatarView];
  33. [self.baseView addSubview:self.userNicknameLb];
  34. [self.baseView addSubview:self.userRankingDifferenceLb];
  35. [self.baseView addSubview:self.onlineStatusView];
  36. [self setNeedsUpdateConstraints];
  37. [self updateConstraintsIfNeeded];
  38. }
  39. - (void)updateConstraints {
  40. [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.top.equalTo(self.contentView);
  42. make.left.equalTo(self.contentView).offset(15);
  43. make.right.equalTo(self.contentView).offset(-5);
  44. make.bottom.equalTo(self.contentView);
  45. }];
  46. [self.userRankingNoLb mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.centerY.equalTo(self.baseView.mas_centerY);
  48. make.left.equalTo(self.baseView).offset(adapt(0));
  49. }];
  50. [self.userAvatarView mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.centerY.equalTo(self.baseView.mas_centerY);
  52. make.left.equalTo(self.userRankingNoLb.mas_right).offset(adapt(13));
  53. make.width.height.mas_equalTo(adapt(40));
  54. }];
  55. [self.userNicknameLb mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.top.equalTo(self.userAvatarView.mas_top).offset(2);
  57. make.left.equalTo(self.userAvatarView.mas_right).offset(8);
  58. }];
  59. [self.userRankingDifferenceLb mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.bottom.equalTo(self.userAvatarView.mas_bottom).offset(0);
  61. make.left.equalTo(self.userAvatarView.mas_right).offset(8);
  62. }];
  63. [self.onlineStatusView mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.centerY.equalTo(self.userNicknameLb.mas_centerY);
  65. make.left.equalTo(self.userNicknameLb.mas_right).offset(adapt(10));
  66. }];
  67. [super updateConstraints];
  68. }
  69. - (void)ym_bindViewModel:(YMRankingListCellViewModel*)viewModel{
  70. if (!viewModel) {
  71. return;
  72. }
  73. _viewModel = viewModel;
  74. [self.userAvatarView sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.viewModel.rankingUserAvatar]];
  75. self.userNicknameLb.text = self.viewModel.rankingUserNickname;
  76. self.userRankingNoLb.text = self.viewModel.userRankingNo;
  77. self.userRankingDifferenceLb.text = self.viewModel.rankingUserRankingDifference;
  78. // NSString *textStr = [self.viewModel.rankingUserRankingDifference stringByReplacingOccurrencesOfString:@"距离上名" withString:@"距离前一名"];
  79. // NSRange range = [textStr rangeOfString:@"距离前一名"];
  80. // NSMutableAttributedString *attrm = [[NSMutableAttributedString alloc] initWithString:textStr];
  81. // [attrm addAttributes:@{NSFontAttributeName: LCFont12, NSForegroundColorAttributeName: HexColorFromRGB(0xA2A0B1)} range:range];
  82. // self.userRankingDifferenceLb.attributedText = attrm;
  83. }
  84. - (UIView *)baseView{
  85. if (!_baseView) {
  86. _baseView = [[UIView alloc]init];
  87. }
  88. return _baseView;
  89. }
  90. - (UILabel *)userRankingNoLb{
  91. if (!_userRankingNoLb) {
  92. _userRankingNoLb = [[UILabel alloc]init];
  93. _userRankingNoLb.font = LCBoldFont(18);
  94. _userRankingNoLb.textColor = HexColorFromRGB(0x080808);
  95. _userRankingNoLb.textAlignment = NSTextAlignmentLeft;
  96. }
  97. return _userRankingNoLb;
  98. }
  99. - (UIImageView *)userAvatarView{
  100. if (!_userAvatarView) {
  101. _userAvatarView = [[UIImageView alloc]init];
  102. _userAvatarView.contentMode = UIViewContentModeScaleAspectFill;
  103. _userAvatarView.backgroundColor = UIColor.lightGrayColor;
  104. [_userAvatarView addRectCorner:UIRectCornerAllCorners radius:adapt(40)/2];
  105. }
  106. return _userAvatarView;
  107. }
  108. - (UILabel *)userNicknameLb{
  109. if (!_userNicknameLb) {
  110. _userNicknameLb = [[UILabel alloc]init];
  111. _userNicknameLb.font = LCFont(14);
  112. _userNicknameLb.textColor = HexColorFromRGBA(0x080808,1);
  113. _userNicknameLb.textAlignment = NSTextAlignmentLeft;
  114. _userNicknameLb.text = @"******";
  115. [_userNicknameLb setContentCompressionResistancePriority:(UILayoutPriorityDefaultLow) forAxis:(UILayoutConstraintAxisHorizontal)];
  116. }
  117. return _userNicknameLb;
  118. }
  119. - (UILabel *)userRankingDifferenceLb{
  120. if (!_userRankingDifferenceLb) {
  121. _userRankingDifferenceLb = [[UILabel alloc]init];
  122. _userRankingDifferenceLb.font = LCFont(10);
  123. _userRankingDifferenceLb.textColor = HexColorFromRGBA(0x080808, 0.4);
  124. _userRankingDifferenceLb.textAlignment = NSTextAlignmentLeft;
  125. _userRankingDifferenceLb.text = @"距离上一名: ****";
  126. [_userRankingDifferenceLb setContentCompressionResistancePriority:(UILayoutPriorityDefaultHigh) forAxis:(UILayoutConstraintAxisHorizontal)];
  127. }
  128. return _userRankingDifferenceLb;
  129. }
  130. - (UIImageView *)onlineStatusView{
  131. if (!_onlineStatusView) {
  132. _onlineStatusView = [[UIImageView alloc]init];
  133. }
  134. return _onlineStatusView;
  135. }
  136. @end