SDCycleScrollView+RQExtension.m 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // SDCycleScrollView+RQExtension.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2022/8/10.
  6. // Copyright © 2022 JCZ. All rights reserved.
  7. //
  8. #import "SDCycleScrollView+RQExtension.h"
  9. #import <objc/runtime.h>
  10. #import "SDCollectionViewCell.h"
  11. @implementation SDCycleScrollView (RQExtension)
  12. @dynamic imagePathsGroup;
  13. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  14. {
  15. long itemIndex = [self pageControlIndexWithCurrentCellIndex:indexPath.item];
  16. NSString *imagePath = self.imagePathsGroup[itemIndex];
  17. if ([imagePath isEqualToString:@"RQ-AD"]) {
  18. RQADCell *cell = [RQADCell cellWithCollectionView:collectionView forIndexPath:indexPath];
  19. return cell;
  20. } else {
  21. SDCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SDCycleScrollViewCell" forIndexPath:indexPath];
  22. if ([self.delegate respondsToSelector:@selector(setupCustomCell:forIndex:cycleScrollView:)] &&
  23. [self.delegate respondsToSelector:@selector(customCollectionViewCellClassForCycleScrollView:)] && [self.delegate customCollectionViewCellClassForCycleScrollView:self]) {
  24. [self.delegate setupCustomCell:cell forIndex:itemIndex cycleScrollView:self];
  25. return cell;
  26. }else if ([self.delegate respondsToSelector:@selector(setupCustomCell:forIndex:cycleScrollView:)] &&
  27. [self.delegate respondsToSelector:@selector(customCollectionViewCellNibForCycleScrollView:)] && [self.delegate customCollectionViewCellNibForCycleScrollView:self]) {
  28. [self.delegate setupCustomCell:cell forIndex:itemIndex cycleScrollView:self];
  29. return cell;
  30. }
  31. if (!self.onlyDisplayText && [imagePath isKindOfClass:[NSString class]]) {
  32. if ([imagePath hasPrefix:@"http"]) {
  33. [cell.imageView sd_setImageWithURL:[NSURL URLWithString:imagePath] placeholderImage:self.placeholderImage];
  34. } else {
  35. UIImage *image = [UIImage imageNamed:imagePath];
  36. if (!image) {
  37. image = [UIImage imageWithContentsOfFile:imagePath];
  38. }
  39. cell.imageView.image = image;
  40. }
  41. } else if (!self.onlyDisplayText && [imagePath isKindOfClass:[UIImage class]]) {
  42. cell.imageView.image = (UIImage *)imagePath;
  43. }
  44. if (self.titlesGroup.count && itemIndex < self.titlesGroup.count) {
  45. cell.title = self.titlesGroup[itemIndex];
  46. }
  47. if (!cell.hasConfigured) {
  48. cell.titleLabelBackgroundColor = self.titleLabelBackgroundColor;
  49. cell.titleLabelHeight = self.titleLabelHeight;
  50. cell.titleLabelTextAlignment = self.titleLabelTextAlignment;
  51. cell.titleLabelTextColor = self.titleLabelTextColor;
  52. cell.titleLabelTextFont = self.titleLabelTextFont;
  53. cell.hasConfigured = YES;
  54. cell.imageView.contentMode = self.bannerImageViewContentMode;
  55. cell.clipsToBounds = YES;
  56. cell.onlyDisplayText = self.onlyDisplayText;
  57. }
  58. return cell;
  59. }
  60. }
  61. - (int)pageControlIndexWithCurrentCellIndex:(NSInteger)index {
  62. return (int)index % self.imagePathsGroup.count;
  63. }
  64. @end