Files
peko-ios/YuMi/Modules/YMNewHome/View/Cell/XPNewHomePartyCollectionViewCell.m
eggmanQQQ 59db4366a6 1. 同步Android 我的 tag UI
2. 其他优化
2024-07-22 19:29:12 +08:00

245 lines
9.0 KiB
Objective-C

//
// XPNewHomePartyCollectionViewCell.m
// YuMi
//
// Created by duoban on 2023/9/4.
//
#import "XPNewHomePartyCollectionViewCell.h"
#import <SDWebImageFLPlugin/SDWebImageFLPlugin.h>
#import <SVGA.h>
@interface XPNewHomePartyCollectionViewCell()
///背景
@property(nonatomic,strong) NetImageView *avatarView;
///榜单
@property(nonatomic,strong) NetImageView *rankImageView;
///类型
@property(nonatomic,strong) NetImageView *tagavatarView;
///房间名
@property(nonatomic,strong) UILabel *nameView;
@property(nonatomic,strong) UILabel *subView;
///热度
@property(nonatomic,strong) UILabel *heatView;
///热度波浪
@property(nonatomic,strong) UIImageView *heatGifView;
///pk
@property(nonatomic,strong) SVGAParser *parser;
@property(nonatomic,strong) SVGAImageView *pkImageView;
@property (nonatomic, assign) NSInteger membersCount;
@end
@implementation XPNewHomePartyCollectionViewCell
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
[self installUI];
[self installConstraints];
self.membersCount = (kGetScaleWidth(345) - kGetScaleWidth(90))/kGetScaleWidth(20);
for (int i = 0; i < self.membersCount; i++) {
NetImageConfig *config = [[NetImageConfig alloc]init];
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
NetImageView *iconView = [[NetImageView alloc]initWithConfig:config];
iconView.tag = 100 + i;
iconView.layer.cornerRadius = kGetScaleWidth(20)/2;
iconView.layer.masksToBounds = YES;
iconView.layer.borderWidth = 1;
iconView.layer.borderColor = [UIColor whiteColor].CGColor;
iconView.hidden = YES;
[self.contentView addSubview:iconView];
CGFloat left = kGetScaleWidth(90) + i * kGetScaleWidth(16);
[iconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.subView.mas_bottom).mas_offset(kGetScaleWidth(8));
make.leading.mas_equalTo(left);
make.width.height.mas_equalTo(kGetScaleWidth(20));
}];
}
}
return self;
}
-(void)installUI{
self.contentView.backgroundColor = [UIColor whiteColor];
self.contentView.layer.cornerRadius = kGetScaleWidth(10);
self.contentView.layer.masksToBounds = YES;
[self.contentView addSubview:self.avatarView];
[self.contentView addSubview:self.tagavatarView];
[self.contentView addSubview:self.rankImageView];
[self.avatarView addSubview:self.pkImageView];
[self.contentView addSubview:self.nameView];
[self.contentView addSubview:self.subView];
[self.contentView addSubview:self.heatGifView];
[self.contentView addSubview:self.heatView];
@kWeakify(self);
[self.parser parseWithNamed:@"pi_home_new_pk" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
@kStrongify(self);
self.pkImageView.loops = INT_MAX;
self.pkImageView.clearsAfterStop = NO;
self.pkImageView.videoItem = videoItem;
[self.pkImageView startAnimation];
} failureBlock:^(NSError * _Nullable error) {
}];
}
-(void)installConstraints{
[self.avatarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(72));
make.height.mas_equalTo(kGetScaleWidth(72));
make.leading.mas_equalTo(kGetScaleWidth(10));
make.top.mas_equalTo(kGetScaleWidth(10));
}];
[self.rankImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.contentView);
}];
[self.tagavatarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.trailing.mas_equalTo(0);
make.width.mas_equalTo(kGetScaleWidth(62));
make.height.mas_equalTo(kGetScaleWidth(19));
}];
[self.heatView mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(-kGetScaleWidth(8));
make.bottom.mas_equalTo(-kGetScaleWidth(10));
make.height.mas_equalTo(kGetScaleWidth(17));
}];
[self.heatGifView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(14));
make.height.mas_equalTo(kGetScaleWidth(14));
make.trailing.equalTo(self.heatView.mas_leading).mas_offset(-kGetScaleWidth(7));
make.centerY.equalTo(self.heatView);
}];
[self.nameView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(kGetScaleWidth(90));
make.top.mas_equalTo(kGetScaleWidth(10));
make.trailing.equalTo(self.tagavatarView.mas_leading).mas_equalTo(5);
make.height.mas_equalTo(kGetScaleWidth(22));
}];
[self.subView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.equalTo(self.nameView);
make.height.mas_equalTo(kGetScaleWidth(17));
make.top.equalTo(self.nameView.mas_bottom).mas_offset(kGetScaleWidth(5));
}];
[self.pkImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(23));
make.height.mas_equalTo(kGetScaleWidth(22));
make.trailing.mas_equalTo(-kGetScaleWidth(6));
make.bottom.equalTo(self.avatarView.mas_bottom).mas_offset(-kGetScaleWidth(6));
}];
}
- (void)setRoomInfo:(HomePlayRoomModel *)roomInfo{
_roomInfo = roomInfo;
_nameView.text = _roomInfo.title;
_avatarView.imageUrl = _roomInfo.avatar;
@kWeakify(self);
[_tagavatarView loadImageWithUrl:_roomInfo.tagPict completion:^(UIImage * _Nullable image, NSURL * _Nonnull url) {
@kStrongify(self);
self.tagavatarView.image = image;
CGFloat width = kGetScaleWidth(62);
if (image.size.height > 0){
width = image.size.width * kGetScaleWidth(19) / image.size.height;
}
[self.tagavatarView mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(width);
}];
}];
_subView.text = _roomInfo.roomDesc.length > 0 ? _roomInfo.roomDesc : YMLocalizedString(@"XPHomeMineViewController3");
_heatView.text = @(_roomInfo.onlineNum).stringValue;
_rankImageView.image = nil;
_pkImageView.hidden = !_roomInfo.crossPking;
if(_roomInfo.isHourTop1 == YES){
_rankImageView.image = [UIImage getLanguageImage:@"home_hour_no_1"];
}else{
if(_roomInfo.isWeekTop1 == YES){
_rankImageView.image = [UIImage getLanguageImage:@"home_week_no_1"];
}
}
for (int i = 0; i < self.membersCount; i++) {
NetImageView *iconView = [self.contentView viewWithTag:100 + i];
if(i < _roomInfo.micUsers.count){
iconView.hidden = NO;
HomePlayMicUserModel *playModel = _roomInfo.micUsers[i];
iconView.imageUrl = playModel.avatar;
}else{
iconView.hidden = YES;
}
}
[self.heatView mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(self.roomInfo.width);
}];
}
#pragma mark - 懒加载
- (NetImageView *)avatarView{
if(!_avatarView){
NetImageConfig *config = [[NetImageConfig alloc]init];
config.placeHolder = [UIImageConstant defaultEmptyAvatarPlaceholder];
_avatarView = [[NetImageView alloc]initWithConfig:config];
_avatarView.contentMode = UIViewContentModeScaleAspectFill;
[_avatarView setCornerWithLeftTopCorner:kGetScaleWidth(10) rightTopCorner:kGetScaleWidth(10) bottomLeftCorner:kGetScaleWidth(10) bottomRightCorner:kGetScaleWidth(10) size:CGSizeMake(kGetScaleWidth(72), kGetScaleWidth(72))];
}
return _avatarView;
}
- (NetImageView *)rankImageView{
if(!_rankImageView){
_rankImageView = [NetImageView new];
}
return _rankImageView;
}
- (NetImageView *)tagavatarView{
if(!_tagavatarView){
_tagavatarView = [NetImageView new];
}
return _tagavatarView;
}
- (UILabel *)nameView{
if(!_nameView){
_nameView = [UILabel labelInitWithText:@"" font:kFontMedium(15) textColor:UIColorFromRGB(0x1E1E1F)];
}
return _nameView;
}
-(UILabel *)heatView{
if(!_heatView){
_heatView = [UILabel labelInitWithText:@"0" font:kFontMedium(10) textColor:UIColorFromRGB(0x84868A)];
_heatView.textAlignment = NSTextAlignmentRight;
}
return _heatView;
}
- (UIImageView *)heatGifView{
if(!_heatGifView){
_heatGifView = [UIImageView new];
_heatGifView.image = kImage(@"ms_home_heat_icon");
}
return _heatGifView;
}
- (SVGAParser *)parser{
if(!_parser){
_parser = [SVGAParser new];
}
return _parser;
}
- (SVGAImageView *)pkImageView {
if (_pkImageView == nil) {
_pkImageView = [[SVGAImageView alloc]init];
_pkImageView.contentMode = UIViewContentModeScaleToFill;
_pkImageView.hidden = YES;
_pkImageView.backgroundColor = [UIColor clearColor];
}
return _pkImageView;
}
- (UILabel *)subView{
if(!_subView){
_subView = [UILabel labelInitWithText:@"" font:kFontRegular(12) textColor:UIColorFromRGB(0x1E1E1F)];
}
return _subView;
}
@end