1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- //
- // SDCycleScrollView+RQExtension.m
- // jiaPei
- //
- // Created by 张嵘 on 2022/8/10.
- // Copyright © 2022 JCZ. All rights reserved.
- //
- #import "SDCycleScrollView+RQExtension.h"
- #import <objc/runtime.h>
- #import "SDCollectionViewCell.h"
- @implementation SDCycleScrollView (RQExtension)
- @dynamic imagePathsGroup;
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
-
- long itemIndex = [self pageControlIndexWithCurrentCellIndex:indexPath.item];
- NSString *imagePath = self.imagePathsGroup[itemIndex];
- if ([imagePath isEqualToString:@"RQ-AD"]) {
- RQADCell *cell = [RQADCell cellWithCollectionView:collectionView forIndexPath:indexPath];
- return cell;
- } else {
- SDCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SDCycleScrollViewCell" forIndexPath:indexPath];
-
- if ([self.delegate respondsToSelector:@selector(setupCustomCell:forIndex:cycleScrollView:)] &&
- [self.delegate respondsToSelector:@selector(customCollectionViewCellClassForCycleScrollView:)] && [self.delegate customCollectionViewCellClassForCycleScrollView:self]) {
- [self.delegate setupCustomCell:cell forIndex:itemIndex cycleScrollView:self];
- return cell;
- }else if ([self.delegate respondsToSelector:@selector(setupCustomCell:forIndex:cycleScrollView:)] &&
- [self.delegate respondsToSelector:@selector(customCollectionViewCellNibForCycleScrollView:)] && [self.delegate customCollectionViewCellNibForCycleScrollView:self]) {
- [self.delegate setupCustomCell:cell forIndex:itemIndex cycleScrollView:self];
- return cell;
- }
-
-
- if (!self.onlyDisplayText && [imagePath isKindOfClass:[NSString class]]) {
- if ([imagePath hasPrefix:@"http"]) {
- [cell.imageView sd_setImageWithURL:[NSURL URLWithString:imagePath] placeholderImage:self.placeholderImage];
- } else {
- UIImage *image = [UIImage imageNamed:imagePath];
- if (!image) {
- image = [UIImage imageWithContentsOfFile:imagePath];
- }
- cell.imageView.image = image;
- }
- } else if (!self.onlyDisplayText && [imagePath isKindOfClass:[UIImage class]]) {
- cell.imageView.image = (UIImage *)imagePath;
- }
-
- if (self.titlesGroup.count && itemIndex < self.titlesGroup.count) {
- cell.title = self.titlesGroup[itemIndex];
- }
-
- if (!cell.hasConfigured) {
- cell.titleLabelBackgroundColor = self.titleLabelBackgroundColor;
- cell.titleLabelHeight = self.titleLabelHeight;
- cell.titleLabelTextAlignment = self.titleLabelTextAlignment;
- cell.titleLabelTextColor = self.titleLabelTextColor;
- cell.titleLabelTextFont = self.titleLabelTextFont;
- cell.hasConfigured = YES;
- cell.imageView.contentMode = self.bannerImageViewContentMode;
- cell.clipsToBounds = YES;
- cell.onlyDisplayText = self.onlyDisplayText;
- }
-
- return cell;
- }
- }
- - (int)pageControlIndexWithCurrentCellIndex:(NSInteger)index {
- return (int)index % self.imagePathsGroup.count;
- }
- @end
|