第十三篇、OC_UICollectionView的基本配置
- (UICollectionView *) categoryCollectionView { if (! _categoryCollectionView) { // 创建布局 UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init]; layout.itemSize = CGSizeMake(KItemWidth,KItemHeight); layout.minimumInteritemSpacing = KSpace; layout.minimumLineSpacing = KSpace; layout.headerReferenceSize = CGSizeMake(KScreentW,KProductHeaderCellH); _categoryCollectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:layout]; _categoryCollectionView.dataSource = self; _categoryCollectionView.delegate = self; _categoryCollectionView.backgroundColor = [UIColor colorWithRed:234.0/255 green:234.0/255 blue:234.0/255 alpha:1]; // 注册 [_categoryCollectionView registerNib:[UINib nibWithNibName:@"GFBCategoryCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:KProductCell]; [_categoryCollectionView registerNib:[UINib nibWithNibName:@"GFBCategoryCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KProductHeaderCell]; // 设置内边距,添加轮播图 _categoryCollectionView.contentInset = UIEdgeInsetsMake(KBanerH, 0, 0, 0); } return _categoryCollectionView; }