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

256 lines
12 KiB
Objective-C

//
// MewUnlockGiftBroadcastViewCell.m
// xplan-ios
//
// Created by duoban on 2024/1/26.
//
#import "MewUnlockGiftBroadcastViewCell.h"
@interface MewUnlockGiftBroadcastViewCell()
@property(nonatomic,strong) NetImageView *giftImageView;
@property(nonatomic,strong) UILabel *giftNameView;
@property(nonatomic,strong) UILabel *giftPriceView;
@property(nonatomic,strong) UIImageView *unlockIconView;
@property(nonatomic,strong) NetImageView *unlockGiftImageView;
@property(nonatomic,strong) UILabel *unlockTitleView;
@property(nonatomic,strong) UILabel *unlockNumView;
@property(nonatomic,strong) UIView *unlockBgView;
@property(nonatomic,strong) UIView *unlockProgressView;
@end
@implementation MewUnlockGiftBroadcastViewCell
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
[self installUI];
[self installConstraints];
}
return self;
}
-(void)installUI{
self.contentView.layer.cornerRadius = 4;
self.contentView.layer.masksToBounds = YES;
self.contentView.layer.borderColor = UIColorRGBAlpha(0xFFDA24, 1).CGColor;
self.contentView.layer.borderWidth = 0;
self.contentView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.08];
[self.contentView addSubview:self.giftImageView];
[self.contentView addSubview:self.giftNameView];
[self.contentView addSubview:self.giftPriceView];
[self.contentView addSubview:self.unlockGiftImageView];
[self.contentView addSubview:self.unlockTitleView];
[self.contentView addSubview:self.unlockBgView];
[self.unlockBgView addSubview:self.unlockProgressView];
[self.contentView addSubview:self.unlockNumView];
[self.contentView addSubview:self.unlockIconView];
}
-(void)setIsBaseGift:(BOOL)isBaseGift{
_isBaseGift = isBaseGift;
self.giftImageView.hidden = !isBaseGift;
self.giftNameView.hidden = !isBaseGift;
self.giftPriceView.hidden = !isBaseGift;
self.unlockGiftImageView.hidden = isBaseGift;
self.unlockTitleView.hidden = isBaseGift;
self.unlockBgView.hidden = isBaseGift;
self.unlockNumView.hidden = isBaseGift;
self.unlockIconView.hidden = isBaseGift;
}
-(void)installConstraints{
[self.giftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(3);
make.centerY.equalTo(self.contentView);
make.width.height.mas_equalTo(28);
}];
[self.giftNameView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(33);
make.top.mas_equalTo(3);
make.height.mas_equalTo(14);
}];
[self.giftPriceView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(14);
make.left.mas_equalTo(33);
make.height.mas_equalTo(13);
}];
[self.unlockIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(8);
make.left.mas_equalTo(3);
make.top.mas_equalTo(2);
}];
[self.unlockGiftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(28);
make.left.mas_equalTo(3);
make.centerY.equalTo(self.contentView);
}];
[self.unlockTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(33);
make.top.mas_equalTo(3);
make.height.mas_equalTo(14);
}];
[self.unlockNumView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.unlockTitleView.mas_right).mas_offset(3);
make.height.mas_equalTo(13);
make.width.mas_greaterThanOrEqualTo(10);
make.top.mas_equalTo(17);
}];
[self.unlockBgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(33);
make.right.equalTo(self.unlockNumView.mas_left).mas_offset(-2);
make.height.mas_equalTo(6);
make.centerY.equalTo(self.unlockNumView);
}];
[self.unlockProgressView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.bottom.equalTo(self.unlockBgView);
make.width.mas_equalTo(0);
}];
}
-(void)setBaseModel:(MewUnlockBaseGiftModel *)baseModel{
_baseModel = baseModel;
UIFont *font = [UIFont systemFontOfSize:9 weight:UIFontWeightRegular];
NSMutableAttributedString *textAtt = [[NSMutableAttributedString alloc]initWithString:@(_baseModel.goldPrice).stringValue attributes:@{NSFontAttributeName:font,NSForegroundColorAttributeName:UIColorFromRGB(0xCED1DB)}];
UIImage *iconImage = kImage(@"gift_diamond");
NSTextAttachment * attachment = [[NSTextAttachment alloc] init];
attachment.bounds = CGRectMake(0, roundf(font.capHeight - iconImage.size.height)/2.f, iconImage.size.width, iconImage.size.height);;
attachment.image = iconImage;
[textAtt insertAttributedString:[NSMutableAttributedString attributedStringWithAttachment:attachment] atIndex:0];
_giftPriceView.attributedText = textAtt;
_giftImageView.image = nil;
[_giftImageView loadImageWithUrl:_baseModel.giftUrl completion:^(UIImage * _Nonnull image, NSURL * _Nonnull url) {
self.giftImageView.image = image;
}];
_giftNameView.text = _baseModel.giftName;
self.contentView.layer.borderWidth = _baseModel.isSelect ? 1 : 0;
}
- (void)setUnlockModel:(MewUnlockGiftModel *)unlockModel{
_unlockModel = unlockModel;
_unlockGiftImageView.image = nil;
[_unlockGiftImageView loadImageWithUrl:_unlockModel.targetGift.giftUrl completion:^(UIImage * _Nonnull image, NSURL * _Nonnull url) {
self.unlockGiftImageView.image = image;
}];
NSMutableAttributedString *numAtt = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%d/%d",_unlockModel.process,_unlockModel.condition] attributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0xCED1DB),NSFontAttributeName:[UIFont systemFontOfSize:9 weight:UIFontWeightRegular]}];
_unlockNumView.attributedText = numAtt;
if(_unlockModel.condition > 0){
CGFloat value = _unlockModel.process / (CGFloat)_unlockModel.condition;
[self.unlockProgressView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.top.bottom.equalTo(self.unlockBgView);
make.width.equalTo(self.unlockBgView).multipliedBy(value);
}];
}
[self setVeiwLucency:1];
if (_unlockModel.process < _unlockModel.condition){
_unlockIconView.hidden = NO;
[self setVeiwLucency:0.5];
self.contentView.layer.borderColor = UIColorRGBAlpha(0xFFDA24, 0.5).CGColor ;
NSString *text = [NSString stringWithFormat:@"送出 %d个 %@可解锁",_unlockModel.condition,_baseModel.giftName];
NSMutableAttributedString *textAtt = [[NSMutableAttributedString alloc]initWithString:text attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:10 weight:UIFontWeightRegular],NSForegroundColorAttributeName:[UIColor whiteColor]}];
[textAtt addAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0xFFDA24),NSFontAttributeName:[UIFont systemFontOfSize:10 weight:UIFontWeightMedium]} range:[text rangeOfString:[NSString stringWithFormat:@"%d个",_unlockModel.condition]]];
_unlockTitleView.attributedText = textAtt;
}else{
_unlockIconView.hidden = YES;
self.contentView.layer.borderColor = UIColorRGBAlpha(0xFFDA24, 1).CGColor ;
NSString *text = [NSString stringWithFormat:@"送出 %d个 %@已解锁",_unlockModel.condition,_baseModel.giftName];
NSMutableAttributedString *textAtt = [[NSMutableAttributedString alloc]initWithString:text attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:10 weight:UIFontWeightRegular],NSForegroundColorAttributeName:[UIColor whiteColor]}];
[textAtt addAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0xFFDA24),NSFontAttributeName:[UIFont systemFontOfSize:10 weight:UIFontWeightMedium]} range:[text rangeOfString:[NSString stringWithFormat:@"%d个",_unlockModel.condition]]];
_unlockTitleView.attributedText = textAtt;
}
if (!_baseModel.isSelect){
self.contentView.layer.borderWidth = _unlockModel.isSelect ? 1 : 0;
}else{
self.contentView.layer.borderWidth = 0;
}
}
-(void)setVeiwLucency:(CGFloat)alpha{
self.unlockGiftImageView.alpha = alpha;
self.unlockTitleView.alpha = alpha;
self.unlockBgView.alpha = alpha;
self.unlockNumView.alpha = alpha;
self.unlockProgressView.alpha = alpha;
}
#pragma mark - 懒加载
- (NetImageView *)giftImageView{
if(!_giftImageView){
_giftImageView = [NetImageView new];
}
return _giftImageView;
}
- (UILabel *)giftNameView{
if(!_giftNameView){
_giftNameView = [UILabel labelInitWithText:@"甜心草莓" font:[UIFont systemFontOfSize:10 weight:UIFontWeightRegular] textColor:[UIColor whiteColor]];
}
return _giftNameView;
}
- (UILabel *)giftPriceView{
if(!_giftPriceView){
_giftPriceView = [UILabel new];
UIFont *font = [UIFont systemFontOfSize:9 weight:UIFontWeightRegular];
NSMutableAttributedString *textAtt = [[NSMutableAttributedString alloc]initWithString:@"0" attributes:@{NSFontAttributeName:font,NSForegroundColorAttributeName:UIColorFromRGB(0xCED1DB)}];
UIImage *iconImage = kImage(@"gift_diamond");
NSTextAttachment * attachment = [[NSTextAttachment alloc] init];
attachment.bounds = CGRectMake(0, roundf(font.capHeight - iconImage.size.height)/2.f, iconImage.size.width, iconImage.size.height);;
attachment.image = iconImage;
[textAtt insertAttributedString:[NSMutableAttributedString attributedStringWithAttachment:attachment] atIndex:0];
_giftPriceView.attributedText = textAtt;
}
return _giftPriceView;
}
- (UIImageView *)unlockIconView{
if(!_unlockIconView){
_unlockIconView = [UIImageView new];
_unlockIconView.image = kImage(@"room_gift_noble_lock");
}
return _unlockIconView;
}
- (NetImageView *)unlockGiftImageView{
if(!_unlockGiftImageView){
_unlockGiftImageView = [NetImageView new];
}
return _unlockGiftImageView;
}
-(UILabel *)unlockTitleView{
if(!_unlockTitleView){
_unlockTitleView = [UILabel new];
NSMutableAttributedString *textAtt = [[NSMutableAttributedString alloc]initWithString:@"送出 5个 甜心草莓可解锁" attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:10 weight:UIFontWeightRegular],NSForegroundColorAttributeName:[UIColor whiteColor]}];
[textAtt addAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0xFFDA24),NSFontAttributeName:[UIFont systemFontOfSize:10 weight:UIFontWeightMedium]} range:[@"送出 5个 甜心草莓可解锁" rangeOfString:@"5个"]];
_unlockTitleView.attributedText = textAtt;
}
return _unlockTitleView;
}
- (UIView *)unlockBgView{
if(!_unlockBgView){
_unlockBgView = [UIView new];
_unlockBgView.backgroundColor = UIColorFromRGB(0x696D7A);
_unlockBgView.layer.cornerRadius = 3;
_unlockBgView.layer.masksToBounds = YES;
}
return _unlockBgView;
}
- (UIView *)unlockProgressView{
if(!_unlockProgressView){
_unlockProgressView = [UIView new];
_unlockProgressView.backgroundColor = UIColorFromRGB(0xFFDA24);
}
return _unlockProgressView;
}
- (UILabel *)unlockNumView{
if(!_unlockNumView){
_unlockNumView = [UILabel new];
NSMutableAttributedString *textAtt = [[NSMutableAttributedString alloc]initWithString:@"0/0" attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:9 weight:UIFontWeightRegular],NSForegroundColorAttributeName:[UIColor whiteColor]}];
[textAtt addAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0xFFDA24),NSFontAttributeName:[UIFont systemFontOfSize:9 weight:UIFontWeightRegular]} range:[@"0/0" rangeOfString:@"0"]];
_unlockNumView.attributedText = textAtt;
}
return _unlockNumView;
}
@end