Learning iOS D8 2017-10-31

学习UICollectionView

1.添加uicollectionview

Learning iOS D8 2017-10-31_第1张图片
完成配置

tips:

定义collectionview时需要初始化collectionview的布局 因此事先需要对layout进行配置

collectionview与tableview不同,tableview只需要对cell进行register,而collectionview需要对cell header footer进行register 这里register的方法也有细小的区别forCellReuseIdentifier 与 forCellWithReuseIdentifier

register footer/header 时 register(UICollectionReusableView.self, forSupplementaryViewOfKind:UICollectionElementKindSectionHeader, withReuseIdentifier: UICollectionElementKindSectionHeader)    蓝色的UICollectionElementKindSectionHeader 是string类型

2.对header/footer进行设置

extension 该vc 导入UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout  ,UICollectionViewDelegateFlowLayout是控制布局的方法 返回CGSize

Learning iOS D8 2017-10-31_第2张图片

方法viewForSupplementaryElementOfKind用来对header/footer进行设置

UICollectionViewDelegate, UICollectionViewDataSource这两个的用法与tableview相同

3.对不同cell的处理

Learning iOS D8 2017-10-31_第3张图片

tag属性 相当于吧cell的index.row提了出来 方便在其他方法也能调用到tag

明日目标:继续把这个页面做完,包括tapp方法的实现

你可能感兴趣的:(Learning iOS D8 2017-10-31)