UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.itemSize = CGSizeMake(500 * Width_Ratio, 590 * Width_Ratio); // item尺寸 layout.minimumLineSpacing = 24 * Width_Ratio; // 行最小间距 layout.minimumInteritemSpacing = 20 * Width_Ratio; // 列最小间距 layout.sectionInset = UIEdgeInsetsMake(31 * Width_Ratio, (Screen_Width - 1024 * Width_Ratio)/2, 31 * Width_Ratio, (Screen_Width - 1024 * Width_Ratio)/2); // section四边缩进 layout.headerReferenceSize = CGSizeMake(Screen_Width, 535 * Width_Ratio); // headerView的尺寸 UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, Screen_Height) collectionViewLayout:layout]; collectionView.backgroundColor = UIColorFromHex(0xf4f4f4); collectionView.showsVerticalScrollIndicator = NO; collectionView.dataSource = self; collectionView.delegate = self; collectionView.alwaysBounceVertical = YES; [collectionView registerClass:[ClawCollectionViewCell class] forCellWithReuseIdentifier:kHomeViewControllerCellIdenfider]; [collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"collectionHeaderView"]; [self.view addSubview:collectionView];
#pragma mark - UICollectionViewDataSource - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.list.count; // item数量 } - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ ClawCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kHomeViewControllerCellIdenfider forIndexPath:indexPath]; return cell; } // header/footer View - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { UICollectionReusableView *reusableview = nil; reusableview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"collectionHeaderView" forIndexPath:indexPath]; return reusableview; } #pragma mark - UICollectionViewDelegate // 点击item - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { }