Files
peko-ios/YuMi/Modules/YMNewHome/View/Cell/XPHomeBannerTableViewCell.m
eggmanQQQ 627748d230 #916
save code
2024-06-21 01:37:38 +08:00

98 lines
3.2 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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_BannerView;
@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_BannerView];
}
- (void)initSubViewConstraints {
[self.pi_BannerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.contentView).mas_offset(16);
make.bottom.mas_equalTo(self.contentView);
make.leading.trailing.mas_equalTo(self.contentView).inset(15);
}];
}
#pragma mark - SDCycleScrollViewDelegate
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
HomeBannerInfoModel * bannerInfo = [self.bannerList xpSafeObjectAtIndex: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_BannerView.imageURLStringsGroup = array;
[self.pi_BannerView autoScroll];
}
}
}
- (void)setIsMineViewBanner:(BOOL)isMineViewBanner {
[self.pi_BannerView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.bottom.mas_equalTo(self.contentView);
}];
}
- (SDCycleScrollView *)pi_BannerView {
if (!_pi_BannerView) {
_pi_BannerView = [[SDCycleScrollView alloc] init];
_pi_BannerView.backgroundColor = [UIColor clearColor];
_pi_BannerView.layer.cornerRadius = 10;
_pi_BannerView.layer.masksToBounds = YES;
_pi_BannerView.delegate = self;
_pi_BannerView.showPageControl = NO;
_pi_BannerView.autoScrollTimeInterval = 5.0;
_pi_BannerView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
_pi_BannerView.placeholderImage = [UIImageConstant defaultBannerPlaceholder];
// SDCycleScrollView没有适配阿语在RTL下会乱滚都用LTR算了
_pi_BannerView.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
for (UIView *subView in _pi_BannerView.subviews) {
subView.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
}
}
return _pi_BannerView;
}
@end