You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
3.1 KiB
107 lines
3.1 KiB
4 years ago
|
//
|
||
|
// TFDiscoverHeaderView.m
|
||
|
// WXReader
|
||
|
//
|
||
|
// Created by 谢腾飞 on 2020/12/2.
|
||
|
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "TFDiscoverHeaderView.h"
|
||
|
#import "YJBannerView.h"
|
||
|
#import "TFDiscoverHeaderViewCell.h"
|
||
|
|
||
|
@interface TFDiscoverHeaderView ()<YJBannerViewDelegate, YJBannerViewDataSource>
|
||
|
|
||
|
@property (nonatomic ,strong) YJBannerView *normalBannerView;
|
||
|
|
||
|
@property (nonatomic ,strong) NSMutableArray *bannerImageArr;
|
||
|
@end
|
||
|
|
||
|
@implementation TFDiscoverHeaderView
|
||
|
|
||
|
- (instancetype)initWithFrame:(CGRect)frame
|
||
|
{
|
||
|
if (self = [super initWithFrame:frame]) {
|
||
|
self.clipsToBounds = YES;
|
||
|
[self initialize];
|
||
|
[self createSubviews];
|
||
|
}
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
- (void)initialize
|
||
|
{
|
||
|
_bannerImageArr = [NSMutableArray array];
|
||
|
}
|
||
|
|
||
|
- (void)createSubviews
|
||
|
{
|
||
|
self.backgroundColor = kWhiteColor;
|
||
|
|
||
|
[self addSubview:self.normalBannerView];
|
||
|
}
|
||
|
|
||
|
//banner
|
||
|
- (YJBannerView *)normalBannerView
|
||
|
{
|
||
|
if (!_normalBannerView) {
|
||
|
_normalBannerView = [YJBannerView bannerViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH / 4) dataSource:self delegate:self emptyImage:HoldImage placeholderImage:HoldImage selectorString:NSStringFromSelector(@selector(setImageWithURL:placeholder:))];
|
||
|
_normalBannerView.pageControlAliment = PageControlAlimentCenter;
|
||
|
_normalBannerView.repeatCount = 9999;
|
||
|
_normalBannerView.autoDuration = 5.0f;
|
||
|
_normalBannerView.pageControlStyle = PageControlCustom;
|
||
|
_normalBannerView.pageControlDotSize = CGSizeMake(10, 5);
|
||
|
_normalBannerView.customPageControlHighlightImage = [UIImage imageNamed:@"pageControlS"];
|
||
|
_normalBannerView.customPageControlNormalImage = [UIImage imageNamed:@"pageControlN"];
|
||
|
}
|
||
|
return _normalBannerView;
|
||
|
}
|
||
|
|
||
|
- (NSArray *)bannerViewRegistCustomCellClass:(YJBannerView *)bannerView
|
||
|
{
|
||
|
return @[[TFDiscoverHeaderViewCell class]];
|
||
|
}
|
||
|
|
||
|
/** 根据 Index 选择使用哪个 reuseIdentifier */
|
||
|
- (Class)bannerView:(YJBannerView *)bannerView reuseIdentifierForIndex:(NSInteger)index
|
||
|
{
|
||
|
return [TFDiscoverHeaderViewCell class];
|
||
|
}
|
||
|
|
||
|
/** 自定义 View 刷新数据或者其他配置 */
|
||
|
- (UICollectionViewCell *)bannerView:(YJBannerView *)bannerView customCell:(UICollectionViewCell *)customCell index:(NSInteger)index
|
||
|
{
|
||
|
TFDiscoverHeaderViewCell *cell = (TFDiscoverHeaderViewCell *)customCell;
|
||
|
cell.imageURL = [self.bannerImageArr objectOrNilAtIndex:index];
|
||
|
return cell;
|
||
|
}
|
||
|
|
||
|
// 将网络图片或者本地图片 或者混合数组
|
||
|
- (NSArray *)bannerViewImages:(YJBannerView *)bannerView
|
||
|
{
|
||
|
return _bannerImageArr;
|
||
|
}
|
||
|
|
||
|
// 代理方法 点击了哪个bannerView 的 第几个元素
|
||
|
- (void)bannerView:(YJBannerView *)bannerView didSelectItemAtIndex:(NSInteger)index
|
||
|
{
|
||
|
if (self.bannerrImageClickBlock) {
|
||
|
self.bannerrImageClickBlock([self.banner objectOrNilAtIndex:index]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (void)setBanner:(NSArray<TFBannerModel *> *)banner
|
||
|
{
|
||
|
_banner = banner;
|
||
|
|
||
|
[_bannerImageArr removeAllObjects];
|
||
|
|
||
|
for (TFBannerModel *t_model in banner) {
|
||
|
[_bannerImageArr addObject:t_model.image];
|
||
|
}
|
||
|
|
||
|
[_normalBannerView reloadData];
|
||
|
}
|
||
|
|
||
|
@end
|