// // HomePageADHeaderView.m // LN_School // // Created by 张嵘 on 2019/7/9. // Copyright © 2019 Danson. All rights reserved. // #import "HomePageADHeaderView.h" #import "HomePageADCustomCell.h" @interface HomePageADHeaderView () @end @implementation HomePageADHeaderView #pragma mark - Life Cycle - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = UIColor.whiteColor; [self addSubview:self.cycleScrollView]; } return self; } - (void)layoutSubviews { [super layoutSubviews]; [_cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) { make.center.mas_equalTo(self); make.size.mas_equalTo(CGSizeMake(self.bounds.size.width, self.bounds.size.height)); }]; } #pragma mark - - (Class)customCollectionViewCellClassForCycleScrollView:(SDCycleScrollView *)view { return [HomePageADCustomCell class]; } - (void)setupCustomCell:(HomePageADCustomCell *)cell forIndex:(NSInteger)index cycleScrollView:(SDCycleScrollView *)view { if (view.imageURLStringsGroup && view.imageURLStringsGroup.count > 0) { [cell.imageView sd_setImageWithURL:view.imageURLStringsGroup[index] placeholderImage:view.placeholderImage]; } else if (view.localizationImageNamesGroup && view.localizationImageNamesGroup.count > 0) { cell.imageView.image = [UIImage imageNamed:view.localizationImageNamesGroup[index]]; } } #pragma mark - Lazy Load - (SDCycleScrollView *)cycleScrollView { if (!_cycleScrollView) { _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:self.frame shouldInfiniteLoop:YES imageNamesGroup:@[@"defaultImg",@"defaultImg"]]; _cycleScrollView.layer.cornerRadius = 5; _cycleScrollView.clipsToBounds = YES; _cycleScrollView.delegate = self; _cycleScrollView.autoScrollTimeInterval = 5; _cycleScrollView.imageURLStringsGroup = @[@"https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=17825117,2252669969&fm=26&gp=0.jpg",@"https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=17825117,2252669969&fm=26&gp=0.jpg"]; _cycleScrollView.placeholderImage = [UIImage imageNamed:@"defaultImg"]; _cycleScrollView.pageControlBottomOffset = 10 + _cycleScrollView.pageControlBottomOffset; } return _cycleScrollView; } @end