Files
peko-ios/YuMi/Modules/YMNewHome/View/Cell/XPHomeBannerTableViewCell.m
2023-07-21 14:07:04 +08:00

93 lines
3.0 KiB
Objective-C

//
// XPHomeBannerTableViewCell.m
// YuMi
//
// Created by YuMi on 2022/2/21.
// 轮播图
#import "XPHomeBannerTableViewCell.h"
///Third
#import <Masonry/Masonry.h>
#import <SDCycleScrollView/SDCycleScrollView.h>
///Model
#import "HomeBannerInfoModel.h"
#import "NSArray+Safe.h"
#import "UIImageConstant.h"
@interface XPHomeBannerTableViewCell ()<SDCycleScrollViewDelegate>
@property (nonatomic, strong) SDCycleScrollView *pi_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.pi_cycleScrollView];
}
- (void)initSubViewConstraints {
[self.pi_cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.contentView).mas_offset(16);
make.bottom.mas_equalTo(self.contentView);
make.left.right.mas_equalTo(self.contentView).inset(15);
}];
}
#pragma mark - SDCycleScrollViewDelegate
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
HomeBannerInfoModel * bannerInfo = [self.bannerList safeObjectAtIndex1:index];
if (self.delegate && [self.delegate respondsToSelector:@selector(xPHomeBannerTableViewCell:didClickBanner:)]) {
[self.delegate xPHomeBannerTableViewCell:self didClickBanner:bannerInfo];
}
}
#pragma mark - Getters And Setters
- (void)setBannerList:(NSArray<HomeBannerInfoModel *> *)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.pi_cycleScrollView.imageURLStringsGroup = array;
[self.pi_cycleScrollView autoScroll];
}
}
}
- (void)setIsMineViewBanner:(BOOL)isMineViewBanner {
[self.pi_cycleScrollView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.bottom.mas_equalTo(self.contentView);
}];
}
- (SDCycleScrollView *)pi_cycleScrollView {
if (!_pi_cycleScrollView) {
_pi_cycleScrollView = [[SDCycleScrollView alloc] init];
_pi_cycleScrollView.backgroundColor = [UIColor clearColor];
_pi_cycleScrollView.layer.cornerRadius = 10;
_pi_cycleScrollView.layer.masksToBounds = YES;
_pi_cycleScrollView.delegate = self;
_pi_cycleScrollView.showPageControl = NO;
_pi_cycleScrollView.autoScrollTimeInterval = 5.0;
_pi_cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
_pi_cycleScrollView.placeholderImage = [UIImageConstant defalutBannerPlaceholder];
}
return _pi_cycleScrollView;
}
@end