首页 > 移动平台 > 详细

iOS 之UICollectionView

时间:2015-12-01 19:31:21      阅读:195      评论:0      收藏:0      [点我收藏+]

0. 简介

  参考:http://www.cnblogs.com/ios8/p/iOS-UICollectionView.html

  UIICollectionView 必须实现UICollectionDataSource、UICollectionViewDelegate、UICollectionViewDelegateFlowLayout这三个协议。

 

1. 每个Section的个数

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView

 

2. 每个Section里View的个数

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

 

3. 每个UICollectionView展示的内容

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

    static NSString * CellIdentifier = @"GradientCell";

    UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

    cell.backgroundColor = [UIColor colorWithRed:((10 * indexPath.row) / 255.0) green:((20 * indexPath.row)/255.0) blue:((30 * indexPath.row)/255.0) alpha:1.0f];

    return cell;

  }

 

4. 每个UICollectionView的大小

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {  
    return CGSizeMake(96, 100);  
} 

 

5. 每个UICollectionView的margin

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section  {  
    return UIEdgeInsetsMake(5, 5, 5, 5);  
}  

 

6. UICollectionView选中时

//UICollectionView被选中时调用的方法  
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath  {  
    UICollectionViewCell * cell = (UICollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];  
    cell.backgroundColor = [UIColor whiteColor];  
}  

 

7. UICollectionView是否可以被选中

-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath  {  
    return YES;  
}

 

iOS 之UICollectionView

原文:http://www.cnblogs.com/SimonGao/p/5011057.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!