ios UICollectionView简单说明

原谅我记不住写下来好了

UICollectionViewFlowLayout 流式自动布局 继承于UICollectionViewLayout

初始化:[[UICollectionViewFlowLayout alloc]init]

属性说明:

  minimumLineSpacing:cell上下间距

  minimumInteritemSpacing:左右间距

  itemSize:cell的size

  scrollDirection:方向

  sectionInset:模块的边距

  headerReferenceSize:heder尺寸

  footerReferenceSize:footer尺寸

UICollectionView 集合视图

初始化:[[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:flowLayout];

注册cell:[_collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"CollectionViewCell"];

     registerNib:(nullable UINib *)nib forCellWithReuseIdentifier:(NSString *)identifier(xib)
注册reusableView:[_collectionView registerClass:[CollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"reusableView"];

          registerNib:(nullable UINib *)nib forSupplementaryViewOfKind:(NSString *)kind withReuseIdentifier:(NSString *)identifier;

常用代理:UICollectionViewDataSource

       - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section;

     - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;

       - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView;

       - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;

      UICollectionViewDelegate

     - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath

     UICollectionViewDelegateFlowLayout

     - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;

 推荐:UICollectionViewLeftAlignedLayout 使其左对齐 

原文地址:https://www.cnblogs.com/chaochaobuhuifei55/p/5939622.html