UICollectView小例子
来源:互联网 发布:淘宝男装店铺排行榜 编辑:程序博客网 时间:2024/06/05 18:36
实现的效果图如下:
‘
这个collectview有四个section,分别有4,1,4,4个item。
- (void)viewDidLoad
{
[superviewDidLoad];
self.collectView.delegate =self;
self.collectView.dataSource =self;
self.identifys =@[@"cell1",@"cell2",@"cell3",@"cell4"];
NSArray *classes =@[[oneCellclass],[twoCellclass],[threeCellclass],[FourCellclass]];
for (int i =0; i < 4; i++) {
[selfregisterForCellFromClass:classes[i] indentify:self.identifys[i]];
}
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayoutalloc]init];
#warning 设定全局行间距
flowLayout.minimumLineSpacing =20;
flowLayout.headerReferenceSize =CGSizeMake(0,20);
flowLayout.sectionInset =UIEdgeInsetsMake(0,10, 0, 10);
#warning 下面一句是必须要写的
self.collectView.collectionViewLayout = flowLayout;
}
- (void)registerForCellFromClass:(Class)class indentify:(NSString *)indentify
{
[self.collectViewregisterClass:class forCellWithReuseIdentifier:indentify];
}
- (UICollectionViewCell *)returnCellFromIndexPath:(NSIndexPath *)indexPath
{
return [self.collectViewdequeueReusableCellWithReuseIdentifier:self.identifys[indexPath.section]forIndexPath:indexPath];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell;
switch (indexPath.section) {
case kFirst:{
oneCell *cell1 = (oneCell *)[selfreturnCellFromIndexPath:indexPath];
cell1.imageView.image = [UIImageimageNamed:@"20111021190309-565119129.jpg"];
cell1.label.text =@"girl";
cell = cell1;
}
break;
case kSecond: {
twoCell *cell2 = (twoCell *)[selfreturnCellFromIndexPath:indexPath];
cell2.imageView.image = [UIImageimageNamed:@"20111021190309-565119129.jpg"];
cell2.titleLabel.text =@"hello";
cell2.detailLabel.text =@"hi";
cell = cell2;
}
break;
case kThird: {
threeCell *cell3 = (threeCell *)[selfreturnCellFromIndexPath:indexPath];
cell3.label.text =@"nihao";
cell = cell3;
}
break;
case kFour:{
FourCell *cell4 = (FourCell *)[selfreturnCellFromIndexPath:indexPath];
cell4.imageView.image = [UIImageimageNamed:@"20111021190309-565119129.jpg"];
cell = cell4;
}
break;
default:
break;
}
cell.backgroundColor = [UIColorwhiteColor];
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGSize size;
switch (indexPath.section) {
case kFirst:
size =CGSizeMake(140,45);
break;
case kSecond:
size =CGSizeMake(300,80);
break;
case kThird:
size =CGSizeMake(140,40);
break;
case kFour:
size =CGSizeMake(60,60);
break;
default:
break;
}
return size;
}
- UICollectView小例子
- UICollectView
- UICollectView Item间隔调整
- UICollectview一般运用
- UICollectView自定义Layout布局
- 小例子
- UICollectView 简介(代理,数据源)
- 一个Comparable小例子
- 一个Assert小例子
- junit小例子
- WPF--Transform小例子
- WWF 小例子
- javascript小例子
- java一些小例子
- java小例子
- 接口的小例子
- 动态的小例子
- File的小例子
- hdu 1059 Dividing
- 封装续集
- 输入两个整数n和m,从数列1,2,······,n中随意取几个整数,使其和等于m,列出所有的可能组合。
- Android_EditText
- 基于xml配置spring
- UICollectView小例子
- iOS UIslider
- 不区分大小写进行替换
- cocos2d-x3.x之helloWorld
- maven的两个配置文件
- vector容器类型
- java内部类 访问final变量----局部内部类访问局部变量
- centos+VM 安装集群式hadoop
- java里面的集合Collection和Map;