首页 > 其他 > 详细

UICollectionView的基本使用

时间:2014-09-22 10:26:34      阅读:610      评论:0      收藏:0      [点我收藏+]
    self.view.backgroundColor = [UIColor whiteColor];
    
//    UICollectionViewLayout 不能直接使用,给collectionView的cell提前布局  prepareLayout(重写item的方法)
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    //cell的大小item的大小
    flowLayout.itemSize = CGSizeMake(155, 200);
    //横向滚动
//    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    
    //UICollectionView的基本使用
    //参数2:布局文件
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:flowLayout];
    //collectionView也有两个代理
    collectionView.delegate = self;
    collectionView.dataSource = self;
    //背景颜色
    collectionView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:collectionView];
    [collectionView release];
    
    //collectionView必须要提前注册cell类
    [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"aaaa"];
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    //cell的个数   Items;
    return 100;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
//    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"aaaa" forIndexPath:indexPath];
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"aaa" forIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor orangeColor];
    return cell;
    
    
}


本文出自 “小刘_Blog” 博客,请务必保留此出处http://liuyafang.blog.51cto.com/8837978/1556802

UICollectionView的基本使用

原文:http://liuyafang.blog.51cto.com/8837978/1556802

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