Files
yinmeng-ios/xplan-ios/Main/ModuleKit/SendGiftView/View/Cell/XPGiftItemCollectionViewCell.m
2024-01-31 10:43:03 +08:00

368 lines
12 KiB
Objective-C

//
// XPGiftItemCollectionViewCell.m
// xplan-ios
//
// Created by 冯硕 on 2021/11/12.
//
#import "XPGiftItemCollectionViewCell.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "ThemeColor+SendGift.h"
#import "NetImageView.h"
///Model
#import "GiftInfoModel.h"
@interface XPGiftItemCollectionViewCell ()
///礼物图片
@property (nonatomic,strong) NetImageView *giftImageView;
///礼物名称
@property (nonatomic,strong) UILabel *giftNameLabel;
///
@property (nonatomic,strong) UIStackView *priceStackView;
///价格
@property (nonatomic,strong) UILabel *priceLabel;
///💎
@property (nonatomic,strong) UIImageView *logoImageView;
///
@property (nonatomic,strong) UIStackView *tagStackView;
///新的
@property (nonatomic,strong) UIImageView *giftNewImageView;
///特别的
@property (nonatomic,strong) UIImageView *specialImageView;
///限定
@property (nonatomic,strong) UIImageView *limitImageView;
///专属
@property (nonatomic,strong) UIImageView *exclusiveImageView;
///
@property (nonatomic,strong) UIImageView * coverView;
///
@property (nonatomic,strong) UILabel *giftNumLabel;
///贵族icon
@property (nonatomic, strong) NetImageView *nobleIconImageView;
///贵族礼物锁
@property (nonatomic, strong) UIImageView *lockImageView;
@property(nonatomic,strong) NetImageView *tagImageView;
@end
@implementation XPGiftItemCollectionViewCell
- (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.coverView];
[self.contentView addSubview:self.tagStackView];
[self.contentView addSubview:self.giftImageView];
[self.contentView addSubview:self.giftNameLabel];
[self.contentView addSubview:self.priceStackView];
[self.contentView addSubview:self.giftNumLabel];
[self.contentView addSubview:self.nobleIconImageView];
[self.contentView addSubview:self.lockImageView];
[self.contentView addSubview:self.tagImageView];
[self.tagStackView addArrangedSubview:self.exclusiveImageView];
[self.tagStackView addArrangedSubview:self.giftNewImageView];
[self.tagStackView addArrangedSubview:self.limitImageView];
[self.tagStackView addArrangedSubview:self.specialImageView];
[self.priceStackView addArrangedSubview:self.priceLabel];
[self.priceStackView addArrangedSubview:self.logoImageView];
}
- (void)initSubViewConstraints {
[self.tagStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.top.mas_equalTo(self.contentView).inset(3);
make.height.mas_equalTo(14);
}];
[self.coverView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self);
}];
[self.giftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.contentView).offset(18);
make.centerX.mas_equalTo(self.contentView);
make.size.mas_equalTo(CGSizeMake(48, 48));
}];
[self.giftNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.giftImageView.mas_bottom).offset(3);
make.centerX.mas_equalTo(self.giftImageView);
}];
[self.priceStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.giftNameLabel.mas_bottom).offset(5);
make.centerX.equalTo(self.contentView);
make.height.mas_equalTo(10);
}];
[self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(10);
}];
[self.giftNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView).offset(4.5);
make.left.equalTo(self.contentView).offset(6);
}];
[self.nobleIconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(16);
make.right.mas_equalTo(self.tagStackView.mas_left).mas_offset(-2);
make.centerY.mas_equalTo(self.tagStackView);
}];
[self.lockImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(18);
make.top.mas_equalTo(7);
make.width.height.mas_equalTo(9);
}];
[self.tagImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(18);
make.top.mas_equalTo(47);
make.height.mas_equalTo(12);
make.width.mas_equalTo(29);
}];
}
-(void)setVeiwLucency:(CGFloat)alpha{
self.giftImageView.alpha = alpha;
self.giftNameLabel.alpha = alpha;
self.giftNumLabel.alpha = alpha;
self.nobleIconImageView.alpha = alpha;
self.tagImageView.alpha = alpha;
self.exclusiveImageView.alpha = alpha;
self.giftNewImageView.alpha = alpha;
self.limitImageView.alpha = alpha;
self.specialImageView.alpha = alpha;
self.priceLabel.alpha = alpha;
self.logoImageView.alpha = alpha;
}
- (UIImageView *)createImageView:(NSString *)imageName {
UIImageView * imageView = [[UIImageView alloc] init];
imageView.userInteractionEnabled = YES;
imageView.image = [UIImage imageNamed:imageName];
return imageView;
}
#pragma mark - Getters And Setters
- (void)setGiftInfo:(GiftInfoModel *)giftInfo {
_giftInfo = giftInfo;
if (_giftInfo) {
self.giftImageView.imageUrl = giftInfo.giftUrl;
self.tagImageView.image = nil;
[self.tagImageView loadImageWithUrl:giftInfo.giftTag completion:^(UIImage * _Nonnull image, NSURL * _Nonnull url) {
CGFloat height = image.size.height > 0 ? image.size.height : 1;
CGFloat width = image.size.width * 12 / height;
[self.tagImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(18);
make.top.mas_equalTo(47);
make.height.mas_equalTo(12);
make.width.mas_equalTo(width);
}];
}];
self.giftNameLabel.text = _giftInfo.giftName.length > 0 ? _giftInfo.giftName : @"";
self.coverView.hidden = !giftInfo.isSelected;
NSString *strr = [NSString stringWithFormat:@"%ld",(long)_giftInfo.goldPrice];
self.priceLabel.text = strr;
self.giftNumLabel.hidden = giftInfo.count <=0 ;
self.giftNumLabel.text = [NSString stringWithFormat:@"x%ld",(long)giftInfo.count];
self.exclusiveImageView.hidden = !_giftInfo.roomExclude;
self.giftNewImageView.hidden = !_giftInfo.hasLatest;
self.limitImageView.hidden = !_giftInfo.hasTimeLimit;
self.specialImageView.hidden = !_giftInfo.hasEffect;
if (_usingplaceType == SendGiftType_User) {
self.giftNameLabel.textColor = [ThemeColor colorWithHexString:@"#282828"];
self.priceLabel.textColor = [ThemeColor colorWithHexString:@"#878B9C"];
self.giftNumLabel.textColor = [ThemeColor secondTextColor];
self.coverView.image = nil;
self.coverView.layer.borderWidth = 1.5;
self.coverView.layer.borderColor = [ThemeColor colorWithHexString:@"#FFE710"].CGColor;
self.coverView.layer.masksToBounds = YES;
self.coverView.layer.cornerRadius = 10;
} else {
self.giftNameLabel.textColor = [UIColor whiteColor];
self.priceLabel.textColor = [UIColor colorWithWhite:1 alpha:0.6];
self.giftNumLabel.textColor = [ThemeColor giftSegmentNormalTitleColor];
self.coverView.layer.borderWidth = 0;
self.coverView.layer.borderColor = [UIColor clearColor].CGColor;
self.coverView.image = [UIImage imageNamed:@"room_gift_slect_bg"];
self.coverView.layer.masksToBounds = YES;
self.coverView.layer.cornerRadius = 0;
}
[self setVeiwLucency:1];
if (giftInfo.giftType == GiftType_Noble && giftInfo.giftVipInfo) {
self.nobleIconImageView.hidden = NO;
self.nobleIconImageView.imageUrl = giftInfo.giftVipInfo.vipIcon;
self.lockImageView.hidden = self.curUserNobleLevel >= giftInfo.giftVipInfo.vipLevel;
[self setVeiwLucency:!self.lockImageView.hidden ? 0.5 : 1];
}else if(giftInfo.giftType == GiftType_Unlock){
self.lockImageView.hidden = YES;
for (int i = 0 ; i < giftInfo.unlockGiftList.count; i++) {
MewUnlockGiftModel *model = giftInfo.unlockGiftList[i];
if (model.targetGift.giftId == giftInfo.giftId){
if (model.process < model.condition){
self.lockImageView.hidden = NO;
[self setVeiwLucency:0.5];
model.unlocked = NO;
}else{
model.unlocked = YES;
}
}
}
}else {
self.nobleIconImageView.hidden = YES;
self.lockImageView.hidden = YES;
}
}
}
- (void)setUsingplaceType:(SendGiftType)usingplaceType {
_usingplaceType = usingplaceType;
}
- (UIStackView *)tagStackView {
if (!_tagStackView) {
_tagStackView = [[UIStackView alloc] init];
_tagStackView.axis = UILayoutConstraintAxisHorizontal;
_tagStackView.distribution = UIStackViewDistributionFill;
_tagStackView.alignment = UIStackViewAlignmentCenter;
_tagStackView.spacing = 2;
}
return _tagStackView;
}
- (UIImageView *)exclusiveImageView {
if (!_exclusiveImageView) {
_exclusiveImageView = [self createImageView:@"gift_tag_exclude"];
}
return _exclusiveImageView;
}
- (UIImageView *)limitImageView {
if (!_limitImageView) {
_limitImageView = [self createImageView:@"gift_tag_time_limit"];
}
return _limitImageView;
}
- (UIImageView *)specialImageView {
if (!_specialImageView) {
_specialImageView = [self createImageView:@"gift_tag_effect"];
}
return _specialImageView;
}
- (UIImageView *)giftNewImageView {
if (!_giftNewImageView) {
_giftNewImageView = [self createImageView:@"gift_tag_latest"];
}
return _giftNewImageView;
}
- (UIStackView *)priceStackView {
if (!_priceStackView) {
_priceStackView = [[UIStackView alloc] init];
_priceStackView.axis = UILayoutConstraintAxisHorizontal;
_priceStackView.distribution = UIStackViewDistributionEqualSpacing;
_priceStackView.alignment = UIStackViewAlignmentCenter;
_priceStackView.spacing = 2;
}
return _priceStackView;
}
- (UIImageView *)logoImageView {
if (!_logoImageView) {
_logoImageView = [self createImageView:@"common_diamond"];
}
return _logoImageView;
}
- (UILabel *)priceLabel {
if (!_priceLabel) {
_priceLabel = [[UILabel alloc] init];
_priceLabel.font = [UIFont systemFontOfSize:9];
_priceLabel.textColor = [ThemeColor giftPriceNormalColor];
}
return _priceLabel;
}
- (UILabel *)giftNameLabel {
if (!_giftNameLabel) {
_giftNameLabel = [[UILabel alloc] init];
_giftNameLabel.font = [UIFont systemFontOfSize:10 weight:UIFontWeightSemibold];
_giftNameLabel.textAlignment = NSTextAlignmentCenter;
_giftNameLabel.textColor = [UIColor whiteColor];
}
return _giftNameLabel;
}
- (UILabel *)giftNumLabel {
if (!_giftNumLabel) {
_giftNumLabel = [[UILabel alloc] init];
_giftNumLabel.font = [UIFont systemFontOfSize:10];
_giftNumLabel.textColor = [UIColor colorWithWhite:1 alpha:0.6];
}
return _giftNumLabel;
}
- (UIImageView *)coverView {
if (!_coverView) {
_coverView = [[UIImageView alloc] init];
_coverView.image = [UIImage imageNamed:@"room_gift_slect_bg"];
_coverView.hidden = YES;
}
return _coverView;
}
- (NetImageView *)giftImageView {
if (!_giftImageView) {
_giftImageView = [[NetImageView alloc] init];
_giftImageView.backgroundColor = [UIColor clearColor];
_giftImageView.layer.masksToBounds = YES;
_giftImageView.contentMode = UIViewContentModeScaleAspectFit;
}
return _giftImageView;
}
- (NetImageView *)nobleIconImageView {
if (!_nobleIconImageView) {
_nobleIconImageView = [[NetImageView alloc] init];
_nobleIconImageView.backgroundColor = [UIColor clearColor];
_nobleIconImageView.hidden = YES;
_nobleIconImageView.contentMode = UIViewContentModeScaleAspectFit;
}
return _nobleIconImageView;
}
- (UIImageView *)lockImageView {
if (!_lockImageView) {
_lockImageView = [self createImageView:@"room_gift_noble_lock"];
_lockImageView.hidden = YES;
}
return _lockImageView;
}
- (NetImageView *)tagImageView{
if(!_tagImageView){
_tagImageView = [NetImageView new];
}
return _tagImageView;
}
@end