123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- //
- // YMRankingListCell.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/14.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMRankingListCell.h"
- #import "YMRankingListCellViewModel.h"
- @interface YMRankingListCell()
- /// ViewModel
- @property (nonatomic, strong) YMRankingListCellViewModel *viewModel;
- /// 基础视图
- @property (nonatomic, strong) UIView *baseView;
- /// 用户排名标签
- @property (nonatomic, strong) UILabel *userRankingNoLb;
- /// 用户头像视图
- @property (nonatomic, strong) UIImageView *userAvatarView;
- /// 用户昵称标签
- @property (nonatomic, strong) UILabel *userNicknameLb;
- /// 用户排名差异标签
- @property (nonatomic, strong) UILabel *userRankingDifferenceLb;
- /// 在线状态视图
- @property (nonatomic, strong) UIImageView *onlineStatusView;
- @end
- @implementation YMRankingListCell
- - (void)ym_setupViews{
- self.backgroundColor = UIColor.clearColor;
- self.contentView.backgroundColor = UIColor.clearColor;
-
- [self.contentView addSubview:self.baseView];
- [self.baseView addSubview:self.userRankingNoLb];
- [self.baseView addSubview:self.userAvatarView];
- [self.baseView addSubview:self.userNicknameLb];
- [self.baseView addSubview:self.userRankingDifferenceLb];
- [self.baseView addSubview:self.onlineStatusView];
-
- [self setNeedsUpdateConstraints];
- [self updateConstraintsIfNeeded];
- }
- - (void)updateConstraints {
- [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView);
- make.left.equalTo(self.contentView).offset(15);
- make.right.equalTo(self.contentView).offset(-5);
- make.bottom.equalTo(self.contentView);
- }];
-
- [self.userRankingNoLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.baseView.mas_centerY);
- make.left.equalTo(self.baseView).offset(adapt(0));
- }];
-
- [self.userAvatarView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.baseView.mas_centerY);
- make.left.equalTo(self.userRankingNoLb.mas_right).offset(adapt(13));
- make.width.height.mas_equalTo(adapt(40));
- }];
-
- [self.userNicknameLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.userAvatarView.mas_top).offset(2);
- make.left.equalTo(self.userAvatarView.mas_right).offset(8);
- }];
-
- [self.userRankingDifferenceLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(self.userAvatarView.mas_bottom).offset(0);
- make.left.equalTo(self.userAvatarView.mas_right).offset(8);
- }];
-
- [self.onlineStatusView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.userNicknameLb.mas_centerY);
- make.left.equalTo(self.userNicknameLb.mas_right).offset(adapt(10));
- }];
- [super updateConstraints];
- }
- - (void)ym_bindViewModel:(YMRankingListCellViewModel*)viewModel{
- if (!viewModel) {
- return;
- }
- _viewModel = viewModel;
-
- [self.userAvatarView sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.viewModel.rankingUserAvatar]];
- self.userNicknameLb.text = self.viewModel.rankingUserNickname;
- self.userRankingNoLb.text = self.viewModel.userRankingNo;
- self.userRankingDifferenceLb.text = self.viewModel.rankingUserRankingDifference;
- // NSString *textStr = [self.viewModel.rankingUserRankingDifference stringByReplacingOccurrencesOfString:@"距离上名" withString:@"距离前一名"];
- // NSRange range = [textStr rangeOfString:@"距离前一名"];
- // NSMutableAttributedString *attrm = [[NSMutableAttributedString alloc] initWithString:textStr];
- // [attrm addAttributes:@{NSFontAttributeName: LCFont12, NSForegroundColorAttributeName: HexColorFromRGB(0xA2A0B1)} range:range];
- // self.userRankingDifferenceLb.attributedText = attrm;
- }
- - (UIView *)baseView{
- if (!_baseView) {
- _baseView = [[UIView alloc]init];
- }
- return _baseView;
- }
- - (UILabel *)userRankingNoLb{
- if (!_userRankingNoLb) {
- _userRankingNoLb = [[UILabel alloc]init];
- _userRankingNoLb.font = LCBoldFont(18);
- _userRankingNoLb.textColor = HexColorFromRGB(0x080808);
- _userRankingNoLb.textAlignment = NSTextAlignmentLeft;
- }
- return _userRankingNoLb;
- }
- - (UIImageView *)userAvatarView{
- if (!_userAvatarView) {
- _userAvatarView = [[UIImageView alloc]init];
- _userAvatarView.contentMode = UIViewContentModeScaleAspectFill;
- _userAvatarView.backgroundColor = UIColor.lightGrayColor;
- [_userAvatarView addRectCorner:UIRectCornerAllCorners radius:adapt(40)/2];
- }
- return _userAvatarView;
- }
- - (UILabel *)userNicknameLb{
- if (!_userNicknameLb) {
- _userNicknameLb = [[UILabel alloc]init];
- _userNicknameLb.font = LCFont(14);
- _userNicknameLb.textColor = HexColorFromRGBA(0x080808,1);
- _userNicknameLb.textAlignment = NSTextAlignmentLeft;
- _userNicknameLb.text = @"******";
- [_userNicknameLb setContentCompressionResistancePriority:(UILayoutPriorityDefaultLow) forAxis:(UILayoutConstraintAxisHorizontal)];
- }
- return _userNicknameLb;
- }
- - (UILabel *)userRankingDifferenceLb{
- if (!_userRankingDifferenceLb) {
- _userRankingDifferenceLb = [[UILabel alloc]init];
- _userRankingDifferenceLb.font = LCFont(10);
- _userRankingDifferenceLb.textColor = HexColorFromRGBA(0x080808, 0.4);
- _userRankingDifferenceLb.textAlignment = NSTextAlignmentLeft;
- _userRankingDifferenceLb.text = @"距离上一名: ****";
- [_userRankingDifferenceLb setContentCompressionResistancePriority:(UILayoutPriorityDefaultHigh) forAxis:(UILayoutConstraintAxisHorizontal)];
- }
- return _userRankingDifferenceLb;
- }
- - (UIImageView *)onlineStatusView{
- if (!_onlineStatusView) {
- _onlineStatusView = [[UIImageView alloc]init];
- }
- return _onlineStatusView;
- }
- @end
|