您的位置:首页 > 其它

collectionView 循环滚动 基本使用

2015-12-22 00:00 162 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: