项目作者: doingself

项目描述 :
UICollectionViewLayout UICollectionViewFlowLayout 自定义布局及切换
高级语言: Swift
项目地址: git://github.com/doingself/CollectionViewLayoutDemo.git
创建时间: 2018-01-05T06:45:44Z
项目社区:https://github.com/doingself/CollectionViewLayoutDemo

开源协议:MIT License

下载


CollectionViewLayoutDemo

UIcollectionView 自定义布局及切换

系统默认 UICollectionViewLayout

  1. layout3 = UICollectionViewFlowLayout()
  2. layout3.itemSize = CGSize(width: (self.view.bounds.size.width/2-20), height: 200)
  3. // layout3... 或者通过代理 UICollectionViewDelegateFlowLayout 方法去实现

自定义 UICollectionViewLayout

重写 layoutAttributesForElementslayoutAttributesForItem 设置 frame

自定义 UICollectionViewFlowLayout

重写 prepare 设置 frame

切换 Layout

  1. if tag == 1{
  2. collectView.setCollectionViewLayout(layout1, animated: true)
  3. }else if tag == 2{
  4. collectView.setCollectionViewLayout(layout2, animated: true)
  5. }else {
  6. collectView.setCollectionViewLayout(layout3, animated: true)
  7. }

Requirements

  • Swift 4
  • iOS 10+
  • Xcode 9+

鸣谢