// // XPHomeBannerTableViewCell.m // xplan-ios // // Created by 冯硕 on 2022/2/21. // 轮播图 #import "XPHomeBannerTableViewCell.h" ///Third #import #import ///Model #import "HomeBannerInfoModel.h" @interface XPHomeBannerTableViewCell () @property (nonatomic, strong) SDCycleScrollView *cycleScrollView; @end @implementation XPHomeBannerTableViewCell - (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.cycleScrollView]; } - (void)initSubViewConstraints { [self.cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.contentView); make.bottom.mas_equalTo(self.contentView).offset(-10); make.left.right.mas_equalTo(self.contentView).inset(15); }]; } #pragma mark - SDCycleScrollViewDelegate - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index { HomeBannerInfoModel * bannerInfo = [self.bannerList objectAtIndex:index]; if (self.delegate && [self.delegate respondsToSelector:@selector(xPHomeBannerTableViewCell:didClickBanner:)]) { [self.delegate xPHomeBannerTableViewCell:self didClickBanner:bannerInfo]; } } #pragma mark - Getters And Setters - (void)setBannerList:(NSArray *)bannerList { _bannerList = bannerList; if (_bannerList.count > 0) { NSMutableArray * array = [NSMutableArray array]; [_bannerList enumerateObjectsUsingBlock:^(HomeBannerInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if (obj.bannerPic.length > 0) { [array addObject:obj.bannerPic]; } }]; if (array.count > 0) { self.cycleScrollView.imageURLStringsGroup = array; [self.cycleScrollView autoScroll]; } } } - (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 = 5.0; } return _cycleScrollView; } @end