九宮格實現水平滾動,系統的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];