口袋优选

KBInviteBannerView.m 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // KBInviteBannerView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/19.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBInviteBannerView.h"
  9. #import "WLScrollView.h"
  10. @interface KBInviteBannerView ()<WLScrollViewDelegate>{
  11. WLScrollView *wlScrView;
  12. }
  13. @end
  14. @implementation KBInviteBannerView
  15. - (instancetype)initWithFrame:(CGRect)frame {
  16. self = [super initWithFrame:frame];
  17. if (self) {
  18. self.layer.masksToBounds = YES;
  19. [self initSubViews];
  20. }
  21. return self;
  22. }
  23. - (void)initSubViews {
  24. wlScrView = [[WLScrollView alloc]initWithFrame:self.bounds];
  25. wlScrView.delegate = self;
  26. wlScrView.isAnimation = YES;
  27. //是否轮播。轮播设置为NO 或者不设置
  28. wlScrView.isEnableMargin = YES;
  29. wlScrView.scale = 0.7;
  30. wlScrView.marginX = 0;
  31. wlScrView.maxAnimationScale = 1;
  32. wlScrView.minAnimationScale = 0.8;
  33. wlScrView.backgroundColor = [UIColor clearColor];
  34. }
  35. #pragma mark - WLScrollViewDelegate
  36. - (NSInteger)numOfContentViewScrollView:(WLScrollView *)scrollView{
  37. return self.dataArr.count;
  38. }
  39. - (WLSubView *)scrollView:(WLScrollView *)scrollView subViewFrame:(CGRect)frame cellAtIndex:(NSInteger)index{
  40. WLSubView *view = [[WLSubView alloc] initWithFrame:frame Identifier:@"cellId"];
  41. view.backgroundColor = [UIColor yhGrayColor];
  42. view.tag = 1000+index;
  43. UIImageView *imgView=[[UIImageView alloc]initWithFrame:view.bounds];
  44. [imgView sd_setImageWithURL:[NSURL URLWithString:self.dataArr[index]]];
  45. [view addSubview:imgView];
  46. return view;
  47. }
  48. - (void)scrollView:(WLScrollView *)scrollView didSelectedAtIndex:(NSInteger)index{
  49. NSLog(@"点击 index %zd",index);
  50. }
  51. - (void)scrollView:(WLScrollView *)scrollView didCurrentCellAtIndex:(NSInteger)index{
  52. NSLog(@"现在显示的 index %zd",index);
  53. WLSubView *sub = [self scrollView:scrollView subViewFrame:[wlScrView getSubFrame] cellAtIndex:index];
  54. NSLog(@"%ld",(long)sub.tag);
  55. NSLog(@"%f",wlScrView.width);
  56. if (self.delegate &&[self.delegate respondsToSelector:@selector(didCurrentCellAtIndex:)]) {
  57. [self.delegate didCurrentCellAtIndex:index];
  58. }
  59. }
  60. -(void)setDataArr:(NSArray *)dataArr{
  61. _dataArr=dataArr;
  62. [wlScrView starRender];
  63. [self addSubview:wlScrView];
  64. }
  65. @end