//初始化Layout
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.itemSize = CGSizeMake(kRecommendCellWidth, kRecommendCellHeight);
flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
//flowLayout.minimumLineSpacing = 15; //竖向间隔
flowLayout.minimumInteritemSpacing = 10;//水平间隔
flowLayout.sectionInset = UIEdgeInsetsMake(0,15,0,15);//一个section 上左下右间隔
//初始化collectionView
UICollectionView *collectionView =[[UICollectionView alloc] initWithFrame:CGRectMake(0, 58, MainScreenWidth, kRecommendCellHeight) collectionViewLayout:flowLayout];
_collectionView = collectionView;
[self.contentView addSubview:collectionView];
self.collectionView.dataSource = self;
self.collectionView.delegate = self;
self.collectionView.bounces = YES;
self.collectionView.scrollEnabled = YES;
self.collectionView.backgroundColor = [UIColor yellowColor];
//注册cell
[self.collectionView registerClass:[GJFCHomeRecommendCollectionViewCell class] forCellWithReuseIdentifier:kReuseID];
网友评论