177 lines
5.3 KiB
Objective-C
177 lines
5.3 KiB
Objective-C
//
|
|
// XPHomeAttentionCollectionViewCell.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/3/2.
|
|
//
|
|
|
|
#import "XPHomeAttentionCollectionViewCell.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "NetImageView.h"
|
|
#import "ThemeColor.h"
|
|
#import "UIImage+Utils.h"
|
|
///Model
|
|
#import "HomeLiveRoomModel.h"
|
|
#import "XPMineFootPrintModel.h"
|
|
|
|
@interface XPHomeAttentionCollectionViewCell ()
|
|
///头像
|
|
@property (nonatomic,strong) NetImageView *avatarImageView;
|
|
///昵称
|
|
@property (nonatomic,strong) UILabel *nickLabel;
|
|
///音符背景
|
|
@property (nonatomic, strong) UIImageView *noteBgImageView;
|
|
///直播中
|
|
@property (nonatomic, strong) UILabel *liveLabel;
|
|
///音符动效
|
|
@property (nonatomic,strong) UIImageView *noteImageView;
|
|
///动画的数组
|
|
@property (nonatomic,strong) NSArray *animationArray;
|
|
@end
|
|
|
|
@implementation XPHomeAttentionCollectionViewCell
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
{
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self.contentView addSubview:self.avatarImageView];
|
|
[self.contentView addSubview:self.nickLabel];
|
|
|
|
[self.avatarImageView addSubview:self.noteBgImageView];
|
|
[self.noteBgImageView addSubview:self.noteImageView];
|
|
[self.noteBgImageView addSubview:self.liveLabel];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(56, 56));
|
|
make.centerX.mas_equalTo(self.contentView);
|
|
make.top.mas_equalTo(self.contentView);
|
|
}];
|
|
|
|
[self.noteBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.bottom.mas_equalTo(self.avatarImageView);
|
|
make.height.mas_equalTo(14);
|
|
}];
|
|
|
|
[self.noteImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.noteBgImageView).mas_offset(15);
|
|
make.centerY.mas_equalTo(self.noteBgImageView).mas_offset(-1);
|
|
make.height.mas_equalTo(7);
|
|
make.width.mas_equalTo(8);
|
|
}];
|
|
[self.liveLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.noteImageView.mas_right).mas_offset(2);
|
|
make.centerY.mas_equalTo(self.noteImageView);
|
|
}];
|
|
[self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(self.avatarImageView);
|
|
make.top.mas_equalTo(self.avatarImageView.mas_bottom).offset(4);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setLiveRoom:(HomeLiveRoomModel *)liveRoom {
|
|
_liveRoom = liveRoom;
|
|
if (_liveRoom) {
|
|
self.avatarImageView.imageUrl = _liveRoom.avatar;
|
|
self.nickLabel.text = _liveRoom.nick;
|
|
self.noteBgImageView.hidden = _liveRoom.roomUid <=0;
|
|
self.noteImageView.hidden = _liveRoom.roomUid <=0;
|
|
if (_liveRoom.roomUid > 0) {
|
|
self.noteImageView.animationImages = self.animationArray;
|
|
self.noteImageView.animationDuration = 0.5;
|
|
[self.noteImageView startAnimating];
|
|
}else {
|
|
self.noteImageView.animationImages = nil;
|
|
[self.noteImageView stopAnimating];
|
|
}
|
|
}
|
|
}
|
|
|
|
- (void)setRecordRoom:(XPMineFootPrintModel *)recordRoom {
|
|
_recordRoom = recordRoom;
|
|
if (recordRoom) {
|
|
self.avatarImageView.imageUrl = recordRoom.avatar;
|
|
self.nickLabel.text = recordRoom.title;
|
|
self.noteBgImageView.hidden = YES;
|
|
}
|
|
}
|
|
|
|
- (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 = 56/2;
|
|
_avatarImageView.layer.borderColor = [UIColor whiteColor].CGColor;
|
|
_avatarImageView.layer.borderWidth = 1;
|
|
}
|
|
return _avatarImageView;
|
|
}
|
|
|
|
- (UILabel *)nickLabel {
|
|
if (!_nickLabel) {
|
|
_nickLabel = [[UILabel alloc] init];
|
|
_nickLabel.font = [UIFont systemFontOfSize:12];
|
|
_nickLabel.textColor = [ThemeColor mainTextColor];
|
|
_nickLabel.textAlignment = NSTextAlignmentCenter;
|
|
}
|
|
return _nickLabel;
|
|
}
|
|
|
|
- (UIImageView *)noteBgImageView {
|
|
if (!_noteBgImageView) {
|
|
_noteBgImageView = [[UIImageView alloc] init];
|
|
_noteBgImageView.image = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xFFA936), UIColorFromRGB(0xFFCB47)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(52, 14)];
|
|
}
|
|
return _noteBgImageView;
|
|
}
|
|
|
|
- (UILabel *)liveLabel {
|
|
if (!_liveLabel) {
|
|
_liveLabel = [[UILabel alloc] init];
|
|
_liveLabel.font = [UIFont systemFontOfSize:8 weight:UIFontWeightMedium];
|
|
_liveLabel.textColor = [UIColor whiteColor];
|
|
_liveLabel.text = @"直播";
|
|
}
|
|
return _liveLabel;
|
|
}
|
|
|
|
- (UIImageView *)noteImageView {
|
|
if (!_noteImageView) {
|
|
_noteImageView = [[UIImageView alloc] init];
|
|
_noteImageView.userInteractionEnabled = YES;
|
|
_noteImageView.animationRepeatCount = 0;
|
|
}
|
|
return _noteImageView;
|
|
}
|
|
|
|
- (NSArray *)animationArray {
|
|
if (!_animationArray) {
|
|
NSMutableArray * array = [NSMutableArray array];
|
|
for (int i = 0; i < 10; i++) {
|
|
NSString * imageName = [NSString stringWithFormat:@"home_note_0000%d",i];
|
|
UIImage * image = [UIImage imageNamed:imageName];
|
|
[array addObject:image];
|
|
}
|
|
_animationArray = [array copy];
|
|
}
|
|
return _animationArray;
|
|
}
|
|
|
|
@end
|