minimumLineSpacing:行间距,此属性大小决定上下两个cell的间距
minimumInteritemSpacing:项间距,此属性设置为0,然后通过控制itemSize的大小来控制左右两个cell的间距
最后把collecView的背景设置成分隔线的颜色
- (UICollectionView *)collectionView {
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake((ScreenWidth-42)/3, (ScreenWidth-42)/3);
layout.minimumLineSpacing = 1;
layout.minimumInteritemSpacing = 0;
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(20, 30, RQGScreenWidth-40, RQGScreenWidth-40) collectionViewLayout:layout];
_collectionView.backgroundColor = RGBACOLOR(233, 233, 233, 1);
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.bounces = NO;
_collectionView.showsVerticalScrollIndicator = NO;
}
return _collectionView;
}
网友评论