結合網上的collectionView經常使用佈局整合的collectionView使用工具git
下載地址github
支持五種佈局方式
ZFCollectionViewLayoutType有兩種
ZFCollectionViewLayoutCircleType, //圓形佈局
ZFCollectionViewLayoutStackType //疊加旋轉佈局工具
ZFCollectionViewFlowLayoutType有三種
ZFCollectionViewFlowLayoutRotatePageType, //旋轉佈局
ZFCollectionViewFlowLayoutWaterfallType, //瀑布流佈局
ZFCollectionViewFlowLayoutLineType //線性佈局佈局
1.導入collectionView文件夾下的文件spa
2.在須要使用的地方加入ZFCollectionView 以下:code
ZFCollectionViewLayout *lay =[[ZFCollectionViewLayout alloc] init]; lay.layoutType =layoutType; if (layoutType == ZFCollectionViewLayoutCircleType) { lay.itemSize =CGSizeMake(100, 100); }else{ lay.itemSize =CGSizeMake(200, 200); } collectionV = [[ZFCollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.width) collectionViewLayout:lay]; collectionV.backgroundColor = [UIColor redColor]; collectionV.cellInfos = self.infos; [self.view addSubview:collectionV];
根據需求設置數據 collectionV.cellInfos = self.infos;orm
數據必須是ZFCollectionViewCellModel類 能夠自定義cell 將類名傳給model (若是是使用代碼自定義cell則傳給cellName,xib自定義的cell則傳給xibCellName) 詳見democi
/* 懶加載數據 */ -(NSMutableArray *)infos{ if (_infos == nil) { NSMutableArray *arr =[NSMutableArray arrayWithObjects:@"zhou",@"fei",@"shi",@"ge",@"da",@"hun",@"dan",@"hehe", nil]; NSMutableArray *arr1 =[NSMutableArray arrayWithCapacity:1]; for (int i =0; i < arr.count; i++) { ZFCollectionViewCellModel *model = [[ZFCollectionViewCellModel alloc] init]; model.title = arr[i]; model.imgWidth =100; model.imgHeight =100; if (i != 3) { model.cellName =@"ZFCollectionViewCell"; }else{ // model.cellName =@"ZFCollectionViewCell"; model.imgHeight =150; model.xibCellName =@"xibCollectionViewCell"; } model.imgName =[NSString stringWithFormat:@"%i",i]; [arr1 addObject:model]; } _infos = arr1; } return _infos; }