// // DRInviteBannerView.m // YouHuiProject // // Created by 小花 on 2018/5/19. // Copyright © 2018年 kuxuan. All rights reserved. // #import "DRInviteBannerView.h" #import "WLScrollView.h" @interface DRInviteBannerView (){ WLScrollView *wlScrView; } @end @implementation DRInviteBannerView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.layer.masksToBounds = YES; [self initSubViews]; } return self; } - (void)initSubViews { wlScrView = [[WLScrollView alloc]initWithFrame:self.bounds]; wlScrView.delegate = self; wlScrView.isAnimation = YES; //是否轮播。轮播设置为NO 或者不设置 wlScrView.isEnableMargin = YES; wlScrView.scale = 0.7; wlScrView.marginX = 0; wlScrView.maxAnimationScale = 1; wlScrView.minAnimationScale = 0.8; wlScrView.backgroundColor = [UIColor clearColor]; } #pragma mark - WLScrollViewDelegate - (NSInteger)numOfContentViewScrollView:(WLScrollView *)scrollView{ return self.dataArr.count; } - (WLSubView *)scrollView:(WLScrollView *)scrollView subViewFrame:(CGRect)frame cellAtIndex:(NSInteger)index{ WLSubView *view = [[WLSubView alloc] initWithFrame:frame Identifier:@"cellId"]; view.backgroundColor = [UIColor yhGrayColor]; view.tag = 1000+index; UIImageView *imgView=[[UIImageView alloc]initWithFrame:view.bounds]; [imgView sd_setImageWithURL:[NSURL URLWithString:self.dataArr[index]]]; [view addSubview:imgView]; return view; } - (void)scrollView:(WLScrollView *)scrollView didSelectedAtIndex:(NSInteger)index{ NSLog(@"点击 index %zd",index); } - (void)scrollView:(WLScrollView *)scrollView didCurrentCellAtIndex:(NSInteger)index{ NSLog(@"现在显示的 index %zd",index); WLSubView *sub = [self scrollView:scrollView subViewFrame:[wlScrView getSubFrame] cellAtIndex:index]; NSLog(@"%ld",(long)sub.tag); NSLog(@"%f",wlScrView.width); if (self.delegate &&[self.delegate respondsToSelector:@selector(didCurrentCellAtIndex:)]) { [self.delegate didCurrentCellAtIndex:index]; } } -(void)setDataArr:(NSArray *)dataArr{ _dataArr=dataArr; [wlScrView starRender]; [self addSubview:wlScrView]; } @end