Files
yinmeng-ios/xplan-ios/Main/Mine/View/Cell/MineInfo/XPMineDataSkillCardTableViewCell.m

168 lines
5.8 KiB
Mathematica
Raw Normal View History

2022-04-14 22:02:15 +08:00
//
// XPMineDataSkillCardTableViewCell.m
// xplan-ios
//
// Created by on 2022/4/14.
//
#import "XPMineDataSkillCardTableViewCell.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "ThemeColor.h"
#import "NSArray+Safe.h"
2022-04-14 22:02:15 +08:00
///View
#import "XPMineDataSkillDataCollectionViewCell.h"
@interface XPMineDataSkillCardTableViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource>
///
@property (nonatomic,strong) UIImageView * backImageView;
///
@property (nonatomic,strong) UILabel *titleLabel;
///
@property (nonatomic,strong) UICollectionView *collectionView;
2022-04-15 18:11:39 +08:00
///
@property (nonatomic,strong) UILabel *emptyLabel;
2022-04-14 22:02:15 +08:00
@end
@implementation XPMineDataSkillCardTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
self.backgroundColor = [UIColor clearColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.contentView addSubview:self.backImageView];
[self.backImageView addSubview:self.titleLabel];
[self.backImageView addSubview:self.collectionView];
2022-04-15 18:11:39 +08:00
[self.backImageView addSubview:self.emptyLabel];
2022-04-14 22:02:15 +08:00
}
- (void)initSubViewConstraints {
[self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.contentView).inset(15);
make.top.mas_equalTo(self.contentView);
make.bottom.mas_equalTo(self.contentView).offset(-15);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.backImageView).offset(12);
make.top.mas_equalTo(self.backImageView).offset(12);
}];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.titleLabel);
make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(12);
make.height.mas_equalTo(47);
make.right.mas_equalTo(self.backImageView).offset(-6);
}];
2022-04-15 18:11:39 +08:00
[self.emptyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.backImageView).inset(10);
make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(12);
make.height.mas_equalTo(47);
}];
2022-04-14 22:02:15 +08:00
}
#pragma mark - UICollectionViewDelegate And UICollectionViewDatasource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.datasourece.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
XPMineDataSkillDataCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPMineDataSkillDataCollectionViewCell class]) forIndexPath:indexPath];
cell.skillInfo = [self.datasourece safeObjectAtIndex1:indexPath.row];
2022-04-14 22:02:15 +08:00
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
if (self.datasourece.count > 0) {
MineSkillCardListInfoModel * skillInfo = [self.datasourece safeObjectAtIndex1:indexPath.row];
2022-04-14 22:02:15 +08:00
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineDataSkillCardTableViewCell:didSelectItem:)]) {
[self.delegate xPMineDataSkillCardTableViewCell:self didSelectItem:skillInfo];
}
}
}
#pragma mark - Getters And Setters
- (void)setDatasourece:(NSArray *)datasourece {
_datasourece = datasourece;
2022-04-15 18:11:39 +08:00
if (_datasourece.count > 0) {
self.emptyLabel.hidden = YES;
self.collectionView.hidden = NO;
} else {
self.emptyLabel.hidden = NO;
self.collectionView.hidden = YES;
}
2022-04-14 22:02:15 +08:00
[self.collectionView reloadData];
}
- (UIImageView *)backImageView {
if (!_backImageView) {
_backImageView = [[UIImageView alloc] init];
_backImageView.userInteractionEnabled = YES;
_backImageView.layer.cornerRadius = 10;
_backImageView.backgroundColor =[ThemeColor appCellBackgroundColor];
_backImageView.layer.shadowColor = UIColorFromRGB(0xE4E4E4).CGColor;
_backImageView.layer.shadowOpacity = 1;
_backImageView.layer.shadowOffset = CGSizeMake(0, 2);
_backImageView.layer.shadowRadius = 8;
}
return _backImageView;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.text = @"技能卡";
_titleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
_titleLabel.textColor = [ThemeColor mainTextColor];
}
return _titleLabel;
}
- (UICollectionView *)collectionView{
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.itemSize = CGSizeMake(142, 47);
layout.minimumLineSpacing = 10;
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.dataSource = self;
2022-04-15 18:11:39 +08:00
_collectionView.showsHorizontalScrollIndicator = NO;
2022-04-14 22:02:15 +08:00
_collectionView.delegate = self;
2022-04-15 18:11:39 +08:00
_collectionView.tag = 1005;
2022-04-14 22:02:15 +08:00
_collectionView.backgroundColor = [UIColor clearColor];
[_collectionView registerClass:[XPMineDataSkillDataCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPMineDataSkillDataCollectionViewCell class])];
}
return _collectionView;
}
2022-04-15 18:11:39 +08:00
- (UILabel *)emptyLabel {
if (!_emptyLabel) {
_emptyLabel = [[UILabel alloc] init];
_emptyLabel.text = @"还未添加技能卡喔";
_emptyLabel.font = [UIFont systemFontOfSize:10];
_emptyLabel.textAlignment = NSTextAlignmentCenter;
_emptyLabel.backgroundColor = UIColorFromRGB(0xF4F7FF);
_emptyLabel.layer.masksToBounds = YES;
_emptyLabel.layer.cornerRadius = 8;
_emptyLabel.textColor = [ThemeColor secondTextColor];
}
return _emptyLabel;
}
2022-04-14 22:02:15 +08:00
@end