Files
yinmeng-ios/xplan-ios/Main/Mine/View/Cell/MineInfo/XPMineUserInfoGiftWallCollectionViewCell.m
2022-04-22 15:11:03 +08:00

158 lines
4.8 KiB
Objective-C

//
// XPMineUserInfoGiftWallCollectionViewCell.m
// xplan-ios
//
// Created by 冯硕 on 2022/4/14.
//
#import "XPMineUserInfoGiftWallCollectionViewCell.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "ThemeColor.h"
#import "NetImageView.h"
///Model
#import "UserGiftWallInfoModel.h"
@interface XPMineUserInfoGiftWallCollectionViewCell ()
///礼物的图片
@property (nonatomic,strong) NetImageView *giftImageView;
///礼物的数量
@property (nonatomic,strong) UIButton *numberButton;
///礼物的名
@property (nonatomic,strong) UILabel *giftNameLabel;
///礼物的价值容器
@property (nonatomic,strong) UIStackView *stackView;
///钻石
@property (nonatomic,strong) UIImageView *diamondImageView;
///价格
@property (nonatomic,strong) UILabel *giftPriceLabel;
@end
@implementation XPMineUserInfoGiftWallCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
self.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:self.giftImageView];
[self.contentView addSubview:self.numberButton];
[self.contentView addSubview:self.giftNameLabel];
[self.contentView addSubview:self.stackView];
[self.stackView addArrangedSubview:self.diamondImageView];
[self.stackView addArrangedSubview:self.giftPriceLabel];
}
- (void)initSubViewConstraints {
[self.giftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.contentView).inset(5);
make.top.mas_equalTo(self.contentView);
make.height.mas_equalTo(self.giftImageView.mas_width);
}];
[self.numberButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(55, 15));
make.centerX.mas_equalTo(self.contentView);
make.top.mas_equalTo(self.giftImageView.mas_bottom).offset(2);
}];
[self.giftNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.contentView);
make.top.mas_equalTo(self.numberButton.mas_bottom).offset(10);
}];
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.contentView);
make.top.mas_equalTo(self.giftNameLabel.mas_bottom).offset(3);
}];
[self.diamondImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(13, 13));
}];
}
#pragma mark - Getters And Setters
- (void)setGiftInfo:(UserGiftWallInfoModel *)giftInfo {
_giftInfo = giftInfo;
if (_giftInfo) {
self.giftImageView.imageUrl = _giftInfo.picUrl;
self.giftNameLabel.text = _giftInfo.giftName;
self.giftPriceLabel.text = [NSString stringWithFormat:@"%ld", _giftInfo.giftPrice];
[self.numberButton setTitle:[NSString stringWithFormat:@"%ld", _giftInfo.reciveCount] forState:UIControlStateNormal];
}
}
- (NetImageView *)giftImageView {
if (!_giftImageView) {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.imageType = ImageTypeUserIcon;
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_giftImageView = [[NetImageView alloc] initWithConfig:config];
_giftImageView.contentMode = UIViewContentModeScaleAspectFill;
_giftImageView.layer.masksToBounds = YES;
}
return _giftImageView;
}
- (UIButton *)numberButton {
if (!_numberButton) {
_numberButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_numberButton setBackgroundColor:UIColorRGBAlpha(0xFFC000, 0.2)];
[_numberButton setTitleColor:[ThemeColor appMainColor] forState:UIControlStateNormal];
_numberButton.titleLabel.font = [UIFont systemFontOfSize:10];
_numberButton.layer.masksToBounds = YES;
_numberButton.layer.cornerRadius = 15 / 2;
}
return _numberButton;
}
- (UILabel *)giftNameLabel {
if (!_giftNameLabel) {
_giftNameLabel = [[UILabel alloc] init];
_giftNameLabel.font = [UIFont systemFontOfSize:13];
_giftNameLabel.textColor = [ThemeColor mainTextColor];
_giftNameLabel.textAlignment = NSTextAlignmentCenter;
}
return _giftNameLabel;
}
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.axis = UILayoutConstraintAxisHorizontal;
_stackView.distribution = UIStackViewDistributionFill;
_stackView.alignment = UIStackViewAlignmentFill;
_stackView.spacing = 3;
}
return _stackView;
}
- (UIImageView *)diamondImageView {
if (!_diamondImageView) {
_diamondImageView = [[UIImageView alloc] init];
_diamondImageView.userInteractionEnabled = YES;
_diamondImageView.image = [UIImage imageNamed:@"common_diamond"];
}
return _diamondImageView;
}
- (UILabel *)giftPriceLabel {
if (!_giftPriceLabel) {
_giftPriceLabel = [[UILabel alloc] init];
_giftPriceLabel.font = [UIFont systemFontOfSize:11];
_giftPriceLabel.textColor = [ThemeColor secondTextColor];
}
return _giftPriceLabel;
}
@end