Files
peko-ios/YuMi/Modules/YMNewHome/View/Cell/XPNewHomePlayItemCollectionViewCell.m
2024-04-17 16:02:42 +08:00

172 lines
5.9 KiB
Objective-C

//
// XPNewHomePlayItemCollectionViewCell.m
// YuMi
//
// Created by YuMi on 2022/10/8.
//
#import "XPNewHomePlayItemCollectionViewCell.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "NetImageView.h"
///Model
#import "HomePlayRoomModel.h"
#import <SDWebImageFLPlugin/SDWebImageFLPlugin.h>
@interface XPNewHomePlayItemCollectionViewCell ()
@property(nonatomic,strong) UIView *bgView;
///边框
@property (nonatomic,strong) UIImageView *borderImageView;
///头像
@property (nonatomic,strong) NetImageView *avatarImageView;
///游戏背景
@property(nonatomic,strong) UIImageView *gameBgView;
///游戏图标
@property(nonatomic,strong) UIImageView *gameIconView;
///在线
@property(nonatomic,strong) FLAnimatedImageView *onlineGifView;
///用户名
@property(nonatomic,strong) UILabel *nameView;
@end
@implementation XPNewHomePlayItemCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
self.contentView.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:self.bgView];
[self.bgView addSubview:self.borderImageView];
[self.bgView addSubview:self.avatarImageView];
[self.bgView addSubview:self.gameBgView];
[self.bgView addSubview:self.gameIconView];
[self.bgView addSubview:self.onlineGifView];
[self.bgView addSubview:self.nameView];
}
- (void)initSubViewConstraints {
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.contentView);
}];
[self.borderImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(60));
make.top.mas_equalTo(kGetScaleWidth(6));
make.centerX.equalTo(self.bgView);
}];
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(kGetScaleWidth(52), kGetScaleWidth(52)));
make.center.mas_equalTo(self.borderImageView);
}];
[self.gameBgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(39));
make.width.mas_equalTo(kGetScaleWidth(52));
make.height.mas_equalTo(kGetScaleWidth(23));
make.centerX.equalTo(self.bgView);
}];
[self.gameIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(43));
make.width.mas_equalTo(kGetScaleWidth(28));
make.height.mas_equalTo(kGetScaleWidth(17));
make.centerX.equalTo(self.bgView);
}];
[self.nameView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_lessThanOrEqualTo(kGetScaleWidth(65));
make.centerX.equalTo(self.bgView).mas_offset(kGetScaleWidth(5));
make.height.mas_equalTo(kGetScaleWidth(17));
make.top.equalTo(self.borderImageView.mas_bottom).mas_offset(kGetScaleWidth(3));
}];
[self.onlineGifView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(9));
make.height.mas_equalTo(kGetScaleWidth(8));
make.centerY.equalTo(self.nameView);
make.trailing.equalTo(self.nameView.mas_leading).mas_offset(-kGetScaleWidth(2));
}];
}
#pragma mark - Getters And Setters
- (void)setRoomInfo:(HomePlayRoomModel *)roomInfo {
_roomInfo = roomInfo;
if (_roomInfo != nil) {
self.avatarImageView.imageUrl = _roomInfo.avatar;
self.nameView.text = _roomInfo.title;
self.gameBgView.hidden = _roomInfo.mgId.length == 0 ;
self.gameIconView.hidden = _roomInfo.mgId.length == 0 ;
self.borderImageView.hidden = _roomInfo.mgId.length == 0 ;
}
}
- (UIView *)bgView{
if(!_bgView){
_bgView = [UIView new];
_bgView.backgroundColor = [UIColor whiteColor];
[_bgView setCornerWithLeftTopCorner:kGetScaleWidth(10) rightTopCorner:kGetScaleWidth(10) bottomLeftCorner:kGetScaleWidth(10) bottomRightCorner:kGetScaleWidth(10) size:CGSizeMake(kGetScaleWidth(100), kGetScaleWidth(92))];
}
return _bgView;
}
- (UIImageView *)borderImageView {
if (!_borderImageView) {
_borderImageView = [[UIImageView alloc] init];
_borderImageView.userInteractionEnabled = YES;
_borderImageView.layer.cornerRadius = kGetScaleWidth(60)/2;
_borderImageView.layer.masksToBounds = YES;
_borderImageView.layer.borderWidth = kGetScaleWidth(2);
_borderImageView.layer.borderColor = UIColorFromRGB(0x759FFF).CGColor;
}
return _borderImageView;
}
- (NetImageView *)avatarImageView {
if (!_avatarImageView) {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.imageType = ImageTypeUserIcon;
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_avatarImageView = [[NetImageView alloc] initWithConfig:config];
_avatarImageView.layer.masksToBounds = YES;
_avatarImageView.layer.cornerRadius = kGetScaleWidth(52)/2;
}
return _avatarImageView;
}
- (UIImageView *)gameBgView{
if(!_gameBgView){
_gameBgView = [UIImageView new];
_gameBgView.image = kImage(@"_home_game_bg");
}
return _gameBgView;
}
- (UIImageView *)gameIconView{
if(!_gameIconView){
_gameIconView = [UIImageView new];
_gameIconView.image = [UIImage getLanguageImage:@"_home_game_icon"];
}
return _gameIconView;
}
- (FLAnimatedImageView *)onlineGifView{
if(!_onlineGifView){
_onlineGifView = [FLAnimatedImageView new];
NSData *localData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"home_sound_wave.gif" ofType:nil]];
FLAnimatedImage *animatedImage = [FLAnimatedImage animatedImageWithGIFData:localData];
_onlineGifView.animatedImage = animatedImage;
}
return _onlineGifView;
}
- (UILabel *)nameView{
if(!_nameView){
_nameView = [UILabel labelInitWithText:@"" font:kFontMedium(12) textColor:UIColorFromRGB(0x1F1B4F)];
}
return _nameView;
}
@end