// // XPMineDataSkillCardTableViewCell.m // xplan-ios // // Created by 冯硕 on 2022/4/14. // #import "XPMineDataSkillCardTableViewCell.h" ///Third #import ///Tool #import "ThemeColor.h" #import "NSArray+Safe.h" ///View #import "XPMineDataSkillDataCollectionViewCell.h" @interface XPMineDataSkillCardTableViewCell () ///背景 @property (nonatomic,strong) UIImageView * backImageView; ///标题 @property (nonatomic,strong) UILabel *titleLabel; ///列表 @property (nonatomic,strong) UICollectionView *collectionView; ///空的容器 @property (nonatomic,strong) UIView *emptyView; ///为空 @property (nonatomic,strong) UILabel *emptyLabel; ///箭头 @property (nonatomic,strong) UIImageView *arrowImageView; @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]; [self.backImageView addSubview:self.emptyView]; [self.emptyView addSubview:self.emptyLabel]; [self.emptyView addSubview:self.arrowImageView]; } - (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); }]; [self.emptyView 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); }]; [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); }]; } #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]; 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]; if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineDataSkillCardTableViewCell:didSelectItem:)]) { [self.delegate xPMineDataSkillCardTableViewCell:self didSelectItem:skillInfo]; } } } - (void)tapEmptySkillCard { if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineDataSkillCardTableViewCell:didSelectItem:)]) { [self.delegate xPMineDataSkillCardTableViewCell:self didSelectItem:nil]; } } #pragma mark - Getters And Setters - (void)setDatasourece:(NSArray *)datasourece { _datasourece = datasourece; if (_datasourece.count > 0) { self.emptyView.hidden = YES; self.collectionView.hidden = NO; } else { self.emptyView.hidden = NO; self.collectionView.hidden = YES; } [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; _collectionView.showsHorizontalScrollIndicator = NO; _collectionView.delegate = self; _collectionView.tag = 1005; _collectionView.backgroundColor = [UIColor clearColor]; [_collectionView registerClass:[XPMineDataSkillDataCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPMineDataSkillDataCollectionViewCell class])]; } return _collectionView; } - (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; } - (UILabel *)emptyLabel { if (!_emptyLabel) { _emptyLabel = [[UILabel alloc] init]; _emptyLabel.text = @"还未添加技能卡喔"; _emptyLabel.font = [UIFont systemFontOfSize:12]; _emptyLabel.textAlignment = NSTextAlignmentCenter; _emptyLabel.textColor = [ThemeColor secondTextColor]; _emptyLabel.userInteractionEnabled = YES; } return _emptyLabel; } @end