ASHomeBannerCell.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //
  2. // ASHomeBannerCell.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/6/5.
  6. //
  7. #import "ASHomeBannerCell.h"
  8. #import "WMZBannerView.h"
  9. @interface ASHomeBannerCell ()
  10. @property (nonatomic,strong) UIPageControl *control;
  11. @property (nonatomic, strong) WMZBannerView *bannerV;
  12. @end
  13. @implementation ASHomeBannerCell
  14. - (void)showData:(NSArray <ASJumpModel*>*)arr {
  15. self.control.numberOfPages = arr.count;
  16. self.control.currentPage = 0;
  17. NSMutableArray *images = [NSMutableArray array];
  18. for (ASJumpModel *m in arr) {
  19. [images addObject:m.image];
  20. }
  21. @weakify(self);
  22. CGFloat h = (KScreenWidth-10-30)/335*445;
  23. WMZBannerParam *param = BannerParam()
  24. .wFrameSet(CGRectMake(-20,10, KScreenWidth+20, h))
  25. .wItemSizeSet(CGSizeMake((KScreenWidth-10-30),h))
  26. .wDataSet(images)
  27. .wPlaceholderImageSet(@"product_defualtImg")
  28. .wScaleFactorSet(0.1f)
  29. .wImageFillSet(false)
  30. .wCustomImageRadioSet(8)
  31. .wEventClickSet(^(id anyID,NSInteger index) {
  32. if (arr.count <= index) {
  33. return;
  34. }
  35. ASJumpModel *temp = arr[index];
  36. weak_self.selectCallBack(index, temp.title, temp.link, temp);
  37. })
  38. .wEventScrollEndSet(^(id anyID, NSInteger index, BOOL isCenter, UICollectionViewCell *cell) {
  39. // NSLog(@"滚动到第%ld个,内容:%@",index,anyID);
  40. // [self.control setCurrentPage:index];
  41. })
  42. .wEventDidScrollSet(^(CGPoint offset){
  43. [weak_self.control setCurrentPage:self.bannerV.bannerControl.currentPage];
  44. })
  45. .wSectionInsetSet(UIEdgeInsetsMake(0, 0, 7, 0))
  46. .wHideBannerControlSet(true)
  47. .wScaleSet(true)
  48. //设置item的间距
  49. .wLineSpacingSet(10)
  50. //开启卡片叠加模式
  51. // .wCardOverLapSet(true)
  52. //毛玻璃背景
  53. // .wEffectSet(YES)
  54. //循环
  55. .wRepeatSet(true)
  56. //开启自动滚动
  57. .wAutoScrollSet(YES)
  58. ;
  59. [self.bannerV resetParam:param];
  60. }
  61. - (void)awakeFromNib {
  62. [super awakeFromNib];
  63. // Initialization code
  64. }
  65. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  66. [super setSelected:selected animated:animated];
  67. // Configure the view for the selected state
  68. }
  69. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  70. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  71. if (self) {
  72. self.selectionStyle = UITableViewCellSelectionStyleNone;
  73. [self loadSubV];
  74. }
  75. return self;
  76. }
  77. - (void)loadSubV {
  78. self.backgroundColor = UIColor.whiteColor;
  79. [self.contentView addSubview:self.bannerV];
  80. [self.contentView addSubview:self.control];
  81. CGFloat h = (KScreenWidth-10-30)/335*445;
  82. [self.bannerV mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.top.equalTo(self.contentView.mas_top).offset(10);
  84. make.left.equalTo(self.contentView).offset(-20);
  85. make.right.equalTo(self.contentView).offset(0);
  86. make.height.equalTo([NSNumber numberWithFloat:h]);
  87. }];
  88. [self.control mas_makeConstraints:^(MASConstraintMaker *make) {
  89. make.top.equalTo(self.bannerV.mas_bottom).offset(10);
  90. make.width.equalTo(@280);
  91. make.height.equalTo(@10);
  92. make.centerX.equalTo(self.contentView);
  93. make.bottom.equalTo(self.contentView).offset(-5);
  94. }];
  95. }
  96. // MARK: - subvs
  97. -(WMZBannerView *)bannerV {
  98. if (!_bannerV) {
  99. WMZBannerView *v = [[WMZBannerView alloc] init];
  100. _bannerV = v;
  101. }
  102. return _bannerV;
  103. }
  104. -(UIPageControl *)control {
  105. if (!_control) {
  106. _control = [[UIPageControl alloc] init];
  107. [_control setTintColor:[UIColor colorWithHexString:@"#000000"]];
  108. [_control setPageIndicatorTintColor:[[UIColor colorWithHexString:@"#000000"] colorWithAlphaComponent:0.3] ];
  109. [_control setCurrentPageIndicatorTintColor:[UIColor colorWithHexString:@"#000000"] ];
  110. _control.transform = CGAffineTransformScale(_control.transform, 1.15, 1.15);
  111. }
  112. return _control;
  113. }
  114. @end