开发中的生活iOS Developer

流式布局的简单使用

2016-05-18  本文已影响238人  没有名字就是我的名字

Collection的简单使用

Snip20160518_7.png
Snip20160518_8.png

首先创建一个继承于UICollectionController的控制器###

在controller中添加一个事件并且设置他的frame
创建流式布局
UICollectionViewFlowLayout *layOut = [UICollectionViewFlowLayout alloc] init];

layOut.itemSize = CGSizeMake(100,100);

layOut.sectionInset = UIEdgeInsetsMake(50, 20, 50, 20);
切记在创建控制切的时候一定要有大小
UICollectionController *test = [UICollectionController alloc] initWithCollectionViewLayout:flowLayout];

[self.navigationController pushViewController:cell animated:YES];
接下来在创建的控制器当中实现数据源方法
第一行代码是在ViewDidLoad里面添加的注册单元格的
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];

static NSString * const reuseIdentifier = @"Cell";

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 3;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
-return 6;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
cell.backgroundColor = [UIColor redColor];    
return cell;
}
Snip20160518_7.png
Snip20160518_8.png
上一篇 下一篇

猜你喜欢

热点阅读