UICollectionView的使用和布局方法
来源:互联网 发布:属下知罪by枯目书包网 编辑:程序博客网 时间:2024/05/19 12:25
#import "ViewController.h"#import "CustomCollectionViewCell.h"@interface ViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>@end@implementation ViewController- (void)dealloc { [super dealloc];}- (void)viewDidLoad { [super viewDidLoad]; // 流式布局 UICollectionViewFlowLayout *flowlayout = [[UICollectionViewFlowLayout alloc] init]; // 滑动方向 flowlayout.scrollDirection = UICollectionViewScrollDirectionVertical; // item的大小 flowlayout.itemSize = CGSizeMake(120, 150); // item的最小行间距 flowlayout.minimumLineSpacing = 5; // item的最小列间距 flowlayout.minimumInteritemSpacing = 5;
// collection的核心就是layout, 负责item的大小和位置 UICollectionView *collectView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:flowlayout]; collectView.backgroundColor = [UIColor whiteColor]; collectView.delegate = self; collectView.dataSource = self;// 切记,一定要注册重用池 [collectView registerClass:[CustomCollectionViewCell class] forCellWithReuseIdentifier:@"CustomCollectionViewCellIdentifier"]; [self.view addSubview:collectView]; [collectView release]; }//UICollectionView被选中时调用的方法 -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"item======%d",indexPath.item); NSLog(@"row=======%d",indexPath.row); NSLog(@"section===%d",indexPath.section); }
<pre name="code" class="objc">//返回item的个数 (方法必须实现)- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return 100;}
//cell上显示的内容 (方法必须实现)- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { CustomCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CustomCollectionViewCellIdentifier" forIndexPath:indexPath]; cell.label.text = @"天马行空"; return cell;}
//定义展示的Section的个数 -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 2; }
1 1
- UICollectionView的使用和布局方法
- 自定义UICollectionView的布局
- UICollectionView的布局
- UICollectionView 的布局
- UICollectionView的简单布局
- UICollectionView的自定义布局
- 使用UICollectionView和UITableView混合布局,完成简单天气demo
- 使用UICollectionView进行圆形布局
- 小结:UICollectionView 相关的属性和方法
- UICollectionView的常用属性和方法
- UITableView和UICollectionView的方法学习一
- UICollectionView和UICollectionReusableView的使用(集合视图)
- UICollectionView的多边形布局-蜂窝布局
- UICollectionView入门--使用系统UICollectionViewFlowLayout布局类
- UICollectionView入门--使用系统UICollectionViewFlowLayout布局类
- UICollectionView入门--使用系统UICollectionViewFlowLayout布局类
- UICollectionView入门--使用系统UICollectionViewFlowLayout布局类
- UICollectionView入门--使用系统UICollectionViewFlowLayout布局类
- 第一个java程序
- UVA 11538-Chess Queen简单排列组合
- 批量执行sql语句
- jQuery效果之级联下拉框
- 《Deep Label Distrubution Learning for Appearent Age Estimation》阅读笔记
- UICollectionView的使用和布局方法
- spring DateUtil
- Google Dremel 原理 - 如何能3秒分析1PB
- 对于熵和信息增益的理解
- Vehicle Identification Via Sparse Representation
- ios 设置摇一摇震动
- NSSet的方法,以及与NSArray、NSDicition之间的区别。
- TabBar去除顶部黑线和NavigationBar去除底部黑线
- android studio集成微博出现错误multiple dex file define Lcon/sina/sso/RemoteSSO解决方法