您的位置:首页 > 产品设计 > UI/UE

UICollectionView

2015-08-19 23:21 621 查看
UICollectionView是UITableView的升级版本,对于UITableView来说系统提供的cell上存在一些显示内容,但是UICollectionView的cell干干净净,因此UICollectionView想显示内容必须使用自定义Cell.UITableView只支持单列竖直滚动,UICollectionView可以支持多列并且可以控制滚动方向.//UICollectionViewDelegateFlowLayout//注意:在使用系统提供的布局时,不用设置该协议的代理人,默认直接设置delegate和DataSource
//创建网格化布局
UICollectionViewFlowLayout *flowLayout = [[[UICollectionViewFlowLayout alloc]init]autorelease];
使用瀑布流比较好用,不过这个样式类是创建UICollectionView必备的.
//修改背景颜色(默认背景颜色黑色)
self.collectionView.backgroundColor = [UIColor whiteColor];
//设置cell的尺寸(由布局完成)
flowLayout.itemSize = CGSizeMake((self.view.frame.size.width-30)/2, 100);
如果是瀑布流的话注意是itemWidth
//设置每个分区的边框范围
<pre name="code" class="objc">    flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
//设置最小列间距,最小行间距 这个是最小的哦,如果间距比<span style="font-family: Times;">minimum</span>大,就按间距来,如果间距比<span style="font-family: Times;">minimum</span>小,就按minimum的值.flowLayout.minimumInteritemSpacing = 5;flowLayout.minimumLineSpacing = 10;
set = UIEdgeInsetsMake(10, 10, 10, 10);
//专门返回每个分区的页眉或者是页脚- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString*)kind atIndexPath:(NSIndexPath *)indexPath{if (kind ==UICollectionElementKindSectionHeader) {HeaderCollectionReusableView *header = [collectionViewdequeueReusableSupplementaryViewOfKind:kindwithReuseIdentifier:@"header"forIndexPath:indexPath];header.textLabel.text =@"萌娃";return header;}else{return nil;}}
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: