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"
|
2023-01-04 14:43:47 +08:00
|
|
|
#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;
|
2023-01-04 18:49:02 +08:00
|
|
|
///空的容器
|
|
|
|
@property (nonatomic,strong) UIView *emptyView;
|
2022-04-15 18:11:39 +08:00
|
|
|
///为空
|
|
|
|
@property (nonatomic,strong) UILabel *emptyLabel;
|
2023-01-04 18:49:02 +08:00
|
|
|
///箭头
|
|
|
|
@property (nonatomic,strong) UIImageView *arrowImageView;
|
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];
|
2023-01-04 18:49:02 +08:00
|
|
|
[self.backImageView addSubview:self.emptyView];
|
|
|
|
|
|
|
|
[self.emptyView addSubview:self.emptyLabel];
|
|
|
|
[self.emptyView addSubview:self.arrowImageView];
|
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
|
|
|
|
2023-01-04 18:49:02 +08:00
|
|
|
[self.emptyView mas_makeConstraints:^(MASConstraintMaker *make) {
|
2022-04-15 18:11:39 +08:00
|
|
|
make.left.right.mas_equalTo(self.backImageView).inset(10);
|
|
|
|
make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(12);
|
|
|
|
make.height.mas_equalTo(47);
|
|
|
|
}];
|
2023-01-04 18:49:02 +08:00
|
|
|
|
|
|
|
[self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.size.mas_equalTo(CGSizeMake(6.5, 11));
|
|
|
|
make.centerY.mas_equalTo(self.emptyView);
|
|
|
|
make.right.mas_equalTo(self.emptyView).offset(-5);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.emptyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.centerY.mas_equalTo(self.emptyView);
|
|
|
|
make.centerX.mas_equalTo(self.emptyView);
|
|
|
|
}];
|
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];
|
2023-01-04 14:43:47 +08:00
|
|
|
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) {
|
2023-01-04 14:43:47 +08:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-04 18:49:02 +08:00
|
|
|
- (void)tapEmptySkillCard {
|
|
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineDataSkillCardTableViewCell:didSelectItem:)]) {
|
|
|
|
[self.delegate xPMineDataSkillCardTableViewCell:self didSelectItem:nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-14 22:02:15 +08:00
|
|
|
#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;
|
|
|
|
}
|
2023-01-04 18:49:02 +08:00
|
|
|
|
|
|
|
- (UIView *)emptyView {
|
|
|
|
if (!_emptyView) {
|
|
|
|
_emptyView = [[UIView alloc] init];
|
|
|
|
_emptyView.backgroundColor = UIColorFromRGB(0xF4F7FF);
|
|
|
|
_emptyView.layer.masksToBounds = YES;
|
|
|
|
_emptyView.layer.cornerRadius = 8;
|
|
|
|
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapEmptySkillCard)];
|
|
|
|
[_emptyView addGestureRecognizer:tap];
|
|
|
|
}
|
|
|
|
return _emptyView;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (UIImageView *)arrowImageView {
|
|
|
|
if (!_arrowImageView) {
|
|
|
|
_arrowImageView = [[UIImageView alloc] init];
|
|
|
|
_arrowImageView.userInteractionEnabled = YES;
|
|
|
|
_arrowImageView.image = [UIImage imageNamed:@"common_right_arrow"];
|
|
|
|
}
|
|
|
|
return _arrowImageView;
|
|
|
|
}
|
|
|
|
|
2022-04-15 18:11:39 +08:00
|
|
|
- (UILabel *)emptyLabel {
|
|
|
|
if (!_emptyLabel) {
|
|
|
|
_emptyLabel = [[UILabel alloc] init];
|
|
|
|
_emptyLabel.text = @"还未添加技能卡喔";
|
2023-01-04 18:49:02 +08:00
|
|
|
_emptyLabel.font = [UIFont systemFontOfSize:12];
|
2022-04-15 18:11:39 +08:00
|
|
|
_emptyLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
_emptyLabel.textColor = [ThemeColor secondTextColor];
|
2023-01-04 18:49:02 +08:00
|
|
|
_emptyLabel.userInteractionEnabled = YES;
|
2022-04-15 18:11:39 +08:00
|
|
|
}
|
|
|
|
return _emptyLabel;
|
|
|
|
}
|
2022-04-14 22:02:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
@end
|