当前位置:   article > 正文

collectionView 循环滚动 基本使用

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;

}


转载于:https://my.oschina.net/daniels/blog/549075

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/519810?site
推荐阅读
相关标签
  

闽ICP备14008679号