标签:
-(void)createCell{ scrollerArr = self.infoArray[0]; // 创建 _scrollerView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_SIZE.width, SCROLLERVIEW_HIGHT)]; _scrollerView.contentSize = CGSizeMake(scrollerArr.count * SCREEN_SIZE.width, SCROLLERVIEW_HIGHT); _scrollerView.pagingEnabled = YES; _scrollerView.delegate = self; _scrollerView.bounces = NO; for (int i = 0; i <= scrollerArr.count; i++) { if (i == scrollerArr.count) { WJJScrollerModel * model = scrollerArr[0]; WJJImageView * imageView = [[WJJImageView alloc] initWithFrame:CGRectMake(SCREEN_SIZE.width * scrollerArr.count, 0,SCREEN_SIZE.width, SCROLLERVIEW_HIGHT)]; [imageView setImageWithURL:[NSURL URLWithString:model.app_picpath] placeholderImage:nil]; [_scrollerView addSubview:imageView]; } else { WJJScrollerModel * model = scrollerArr[i]; WJJImageView * imageView = [[WJJImageView alloc] initWithFrame:CGRectMake(SCREEN_SIZE.width * i, 0, SCREEN_SIZE.width, SCROLLERVIEW_HIGHT)]; [imageView setImageWithURL:[NSURL URLWithString:model.app_picpath] placeholderImage:nil]; [_scrollerView addSubview:imageView]; } } pageCon = [[UIPageControl alloc] initWithFrame:CGRectMake(SCREEN_SIZE.width - PAGCONTROLLER_WIDTH, SCROLLERVIEW_HIGHT - 20, PAGCONTROLLER_WIDTH, 20)]; pageCon.numberOfPages = scrollerArr.count; pageCon.pageIndicatorTintColor = [UIColor whiteColor]; pageCon.currentPageIndicatorTintColor = [UIColor redColor]; pageCon.currentPage = 0; [self.contentView addSubview:_scrollerView]; [self.contentView addSubview:pageCon]; } #pragma mark - UIScollerView 代理 -(void)scrollViewDidScroll:(UIScrollView *)scrollView { int currentPage = (_scrollerView.contentOffset.x / SCREEN_SIZE.width) ; if (_scrollerView.contentOffset.x / SCREEN_SIZE.width == scrollerArr.count ) { pageCon.currentPage = 0; [_scrollView setContentOffset:CGPointMake(0, 0) animated:NO]; } else { pageCon.currentPage = currentPage; } } #pragma mark - 定时器 -(void)addTimer { _timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(timerGo) userInfo:nil repeats:YES]; } -(void)timerGo { if (_scrollerView.contentOffset.x / SCREEN_SIZE.width == scrollerArr.count ) { pageCon.currentPage = 0; [_scrollerView setContentOffset:CGPointMake(0, 0) animated:NO]; } else { [_scrollerView setContentOffset:CGPointMake(_scrollerView.contentOffset.x + SCREEN_SIZE.width, 0) animated:YES]; } } -(void)dealloc { if (_timer != nil) { [_timer invalidate]; } }
标签:
原文地址:http://www.cnblogs.com/WJJ-Dream/p/5786979.html