134 lines
4.2 KiB
Objective-C
134 lines
4.2 KiB
Objective-C
//
|
|
// XPMomentTopicHeaderView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by XY on 2023/3/6.
|
|
//
|
|
|
|
#import "XPMomentTopicHeaderView.h"
|
|
#import "ThemeColor.h"
|
|
#import <Masonry.h>
|
|
#import "XPMacro.h"
|
|
#import "NSArray+Safe.h"
|
|
#import <SDCycleScrollView.h>
|
|
///View
|
|
#import "XPMomentTopicHeaderCell.h"
|
|
|
|
@interface XPMomentTopicHeaderView()<SDCycleScrollViewDelegate>
|
|
/// 背景
|
|
@property (nonatomic, strong) UIView *bgView;
|
|
/// 轮播图
|
|
@property (nonatomic, strong) SDCycleScrollView *cycleScrollView;
|
|
|
|
@end
|
|
|
|
@implementation XPMomentTopicHeaderView
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self addSubview:self.bgView];
|
|
[self.bgView addSubview:self.cycleScrollView];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(10);
|
|
make.left.mas_equalTo(15);
|
|
make.right.mas_equalTo(-15);
|
|
make.bottom.mas_equalTo(-10);
|
|
}];
|
|
[self.cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.left.right.bottom.mas_equalTo(0);
|
|
}];
|
|
}
|
|
|
|
+ (CGFloat)getTopicHeaderViewHeight {
|
|
CGFloat width = KScreenWidth-15*2;
|
|
CGFloat height = 74.0/345.0*width;
|
|
return height+20;
|
|
}
|
|
|
|
- (Class)customCollectionViewCellClassForCycleScrollView:(SDCycleScrollView *)view {
|
|
return [XPMomentTopicHeaderCell class];
|
|
}
|
|
|
|
- (void)setupCustomCell:(UICollectionViewCell *)cell forIndex:(NSInteger)index cycleScrollView:(SDCycleScrollView *)view {
|
|
XPMomentTopicHeaderCell *topicCell = (XPMomentTopicHeaderCell *)cell;
|
|
MonentsTopicModel *model = [self.topicList safeObjectAtIndex1:index];
|
|
topicCell.topicModel = model;
|
|
}
|
|
|
|
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(momentTopicHeaderViewClickTopic:)]) {
|
|
MonentsTopicModel *topicModel = [self.topicList safeObjectAtIndex1:index];
|
|
[self.delegate momentTopicHeaderViewClickTopic:topicModel];
|
|
}
|
|
}
|
|
|
|
#pragma mark - UICollectionViewDelegate
|
|
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
return self.topicList.count;
|
|
}
|
|
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
XPMomentTopicHeaderCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPMomentTopicHeaderCell class]) forIndexPath:indexPath];
|
|
MonentsTopicModel *model = [self.topicList safeObjectAtIndex1:indexPath.row];
|
|
cell.topicModel = model;
|
|
return cell;
|
|
}
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(momentTopicHeaderViewClickTopic:)]) {
|
|
MonentsTopicModel *topicModel = [self.topicList safeObjectAtIndex1:indexPath.row];
|
|
[self.delegate momentTopicHeaderViewClickTopic:topicModel];
|
|
}
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
|
|
- (void)setTopicList:(NSArray *)topicList {
|
|
_topicList = topicList;
|
|
NSMutableArray *tempArr = [NSMutableArray array];
|
|
for (int i = 0; i<topicList.count; i++) {
|
|
[tempArr addObject:@""];
|
|
}
|
|
self.cycleScrollView.localizationImageNamesGroup = tempArr;
|
|
[self.cycleScrollView autoScroll];
|
|
}
|
|
|
|
- (UIView *)bgView {
|
|
if (!_bgView) {
|
|
_bgView = [[UIView alloc] init];
|
|
_bgView.backgroundColor = [ThemeColor appCellBackgroundColor];
|
|
_bgView.layer.cornerRadius = 12;
|
|
_bgView.clipsToBounds = YES;
|
|
}
|
|
return _bgView;
|
|
}
|
|
|
|
- (SDCycleScrollView *)cycleScrollView {
|
|
if (!_cycleScrollView) {
|
|
_cycleScrollView = [[SDCycleScrollView alloc] init];
|
|
_cycleScrollView.backgroundColor = [UIColor clearColor];
|
|
_cycleScrollView.layer.cornerRadius = 10;
|
|
_cycleScrollView.layer.masksToBounds = YES;
|
|
_cycleScrollView.delegate = self;
|
|
_cycleScrollView.showPageControl = NO;
|
|
_cycleScrollView.autoScrollTimeInterval = 3.0;
|
|
}
|
|
return _cycleScrollView;
|
|
}
|
|
|
|
|
|
@end
|