九宫格实现水平滚动,系统的UICollectionView满足不了需求,参考网址点击打开链接
.h文件
.m文件
调用
SSLHorizontalPageFlowlayout *
flowLayout = [[SSLHorizontalPageFlowlayout alloc] initWithRowCount:3 itemCountPerRow:4];
[flowLayout setItemSize:CGSizeMake((WIDTH)/4, (WIDTH)/4-10-20)];//设置cell的尺寸
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];//设置其布局方向
flowLayout.minimumInteritemSpacing = 0; //定义左右cell的最小间距
flowLayout.minimumLineSpacing = 0;//定义上下cell的最小间距
flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);//设置其边界
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 5, WIDTH, ((WIDTH)/4-10-20)*3) collectionViewLayout:flowLayout];
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.backgroundColor = [UIColor whiteColor];
[_collectionView registerClass:[SSLHomeItemCell class] forCellWithReuseIdentifier:@"SSLHomeItemCell"];
[self.view addSubview:_collectionView];