140 lines
4.0 KiB
Objective-C
140 lines
4.0 KiB
Objective-C
//
|
|
// XPGiftUserCollectionViewCell.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2021/11/9.
|
|
//
|
|
|
|
#import "XPGiftUserCollectionViewCell.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "ThemeColor+SendGift.h"
|
|
///Model
|
|
#import "UserInfoModel.h"
|
|
#import "MicroStateModel.h"
|
|
#import "XPGiftUserInfoModel.h"
|
|
///View
|
|
#import "NetImageView.h"
|
|
|
|
@interface XPGiftUserCollectionViewCell ()
|
|
///头像
|
|
@property (nonatomic,strong) NetImageView *avatarImageView;
|
|
///背景图
|
|
@property (nonatomic,strong) UIView * coverView;
|
|
///当前位置的
|
|
@property (nonatomic,strong) UILabel *positionLabel;
|
|
@end
|
|
|
|
@implementation XPGiftUserCollectionViewCell
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
if (self = [super initWithFrame:frame]) {
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self.contentView addSubview:self.avatarImageView];
|
|
[self.contentView addSubview:self.coverView];
|
|
[self.contentView addSubview:self.positionLabel];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.top.mas_equalTo(self.contentView);
|
|
make.width.height.mas_equalTo(38);
|
|
}];
|
|
|
|
[self.coverView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self.avatarImageView);
|
|
}];
|
|
|
|
[self.positionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(10);
|
|
make.centerY.mas_equalTo(self.avatarImageView.mas_bottom);
|
|
make.width.mas_equalTo(10);
|
|
make.centerX.mas_equalTo(self.avatarImageView);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setUserInfo:(XPGiftUserInfoModel *)userInfo {
|
|
_userInfo = userInfo;
|
|
if (_userInfo.position.length > 0) {
|
|
|
|
if (_userInfo.vipMic) {
|
|
self.positionLabel.text = @"VIP";
|
|
[self.positionLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_equalTo(28);
|
|
}];
|
|
} else {
|
|
if (_userInfo.position.integerValue == -1) {
|
|
self.positionLabel.text = @"房主位";
|
|
[self.positionLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_equalTo(28);
|
|
}];
|
|
} else {
|
|
self.positionLabel.text = [NSString stringWithFormat:@"%ld", _userInfo.position.integerValue + 1];
|
|
[self.positionLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_equalTo(10);
|
|
}];
|
|
}
|
|
}
|
|
|
|
}
|
|
self.avatarImageView.imageUrl = _userInfo.avatar;
|
|
if (_userInfo.isSelect) {
|
|
self.avatarImageView.layer.borderWidth = 2;
|
|
self.coverView.hidden = YES;
|
|
self.positionLabel.backgroundColor = [ThemeColor appMainColor];
|
|
_positionLabel.textColor = [ThemeColor mainTextColor];
|
|
} else {
|
|
self.avatarImageView.layer.borderWidth = 0;
|
|
self.coverView.hidden = NO;
|
|
self.positionLabel.backgroundColor = [ThemeColor textThirdColor];
|
|
_positionLabel.textColor = [UIColor whiteColor];
|
|
}
|
|
}
|
|
|
|
- (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 = 38/2;
|
|
_avatarImageView.layer.borderColor = [ThemeColor appMainColor].CGColor;
|
|
}
|
|
return _avatarImageView;
|
|
}
|
|
|
|
- (UIView *)coverView {
|
|
if (!_coverView) {
|
|
_coverView = [[UIView alloc] init];
|
|
_coverView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
|
|
_coverView.layer.cornerRadius = 38/2;
|
|
_coverView.layer.masksToBounds = YES;
|
|
}
|
|
return _coverView;
|
|
}
|
|
|
|
- (UILabel *)positionLabel{
|
|
if (!_positionLabel) {
|
|
_positionLabel = [[UILabel alloc] init];
|
|
_positionLabel.font = [UIFont systemFontOfSize:8];
|
|
_positionLabel.textColor = [UIColor whiteColor];
|
|
_positionLabel.textAlignment = NSTextAlignmentCenter;
|
|
_positionLabel.backgroundColor = UIColorFromRGB(0x999999);
|
|
_positionLabel.layer.masksToBounds = YES;
|
|
_positionLabel.layer.cornerRadius = 5;
|
|
}
|
|
return _positionLabel;
|
|
}
|
|
|
|
@end
|