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;
}
[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;
}
相关文章推荐
- CentOS 6.3下Samba服务器的安装与配置
- 负载均衡设计
- eclipse access restriction
- “object name conflicts in archive”的解决办法
- Eclipse安装插件时错误解决方法
- 求数字组合数
- 十进制转为十六进制
- 计数器/定时器8253的基本介绍和功能——(一)
- 计数器/定时器8253的基本介绍和功能——(二)
- 高德地图学习系列
- OSC 职位推荐:借我 3 分钟,还你一个更好的机会
- BlockQueue使用之简单应用
- kali 更新源 sources.list以及apt-get 相关命令说明
- Linux 每日一练习!!!!!!!!!!sleep 表示等待时间
- Linux 每日一练习!!!!!!!!!!删除文件的大灾难,你会碰见吗?
- 写给即将入行的程序员的一封信
- 程序员技术练级攻略
- Git详解之三 Git分支
- 自动连接服务器
- deferred Transports Protocols 简单介绍