collectionView 循环滚动 基本使用

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];

    [flowLayout setItemSize:CGSizeMake(SCREENSIZE.width,156)];

    [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];


    scrollImageView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 94, SCREENSIZE.width,156) collectionViewLayout:flowLayout];

  

    scrollImageView.delegate = self;

    scrollImageView.dataSource = self;


    [scrollImageView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"collection"];

    scrollImageView.showsHorizontalScrollIndicator = NO;

    [self.view addSubview:scrollImageView];


//代理方法

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section

{

    return 1;

}


- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView

{

    return 3000;

}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

{

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collection" forIndexPath:indexPath];

    int i = (int)indexPath.section%self.imageArray.count;

    UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:self.imageArray[i]]];

    image.frame = CGRectMake(0, 0, SCREENSIZE.width, 156);

    [cell.contentView addSubview:image];

    return cell;

}


你可能感兴趣的:(collectionView 循环滚动 基本使用)