码迷,mamicode.com
首页 > 其他好文 > 详细

UICollectionCell

时间:2016-05-03 23:49:50      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

=================

UICollectionView的应用

=================

用于显示方块Cell

代理:<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

 

//布局

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

    //横向间距

    flowLayout.minimumLineSpacing=30;

    //竖向间距

    flowLayout.minimumInteritemSpacing=20;

    //滚动的方向 flowLayout.scrollDirection=UICollectionViewScrollDirectionVertical;

    

 

    //创建UICollectionView

    _collectionView=[[UICollectionView alloc]initWithFrame:CGRectMake(0, 64, KSCREENWIDTH, KSCREENHEIGHT-64-49) collectionViewLayout:flowLayout];

    _collectionView.delegate=self;

    _collectionView.dataSource=self;

    

    _collectionView.backgroundColor=[UIColor whiteColor];

    

    [self.view addSubview:_collectionView];

 

#pragma mark collectionView的代理

//返回每组有多少个对象

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

    return _dataArray.count;

}

 

//返回cell的大小

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{

    return CGSizeMake(60, 80);

}

 

//返回距离四周的边距,上,左,下,右

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{

    return UIEdgeInsetsMake(30, 30, 30, 30);

}

 

//cell的定制

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

    static NSString *cellId=@"cell";

    SetCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath];

    SetModel *model=_dataArray[indexPath.row];

    cell.itemName.text=model.name;

    cell.itemImage.image=[UIImage imageNamed:model.imageUrl];

    return cell;

}

 

 

 

UICollectionCell

标签:

原文地址:http://www.cnblogs.com/tony0571/p/5456715.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!