Skip to content

UICollectionViewLayout UICollectionViewFlowLayout 自定义布局及切换

License

Notifications You must be signed in to change notification settings

doingself/CollectionViewLayoutDemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CollectionViewLayoutDemo

UIcollectionView 自定义布局及切换

系统默认 UICollectionViewLayout

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

自定义 UICollectionViewLayout

重写 layoutAttributesForElementslayoutAttributesForItem 设置 frame

自定义 UICollectionViewFlowLayout

重写 prepare 设置 frame

切换 Layout

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

Requirements

  • Swift 4
  • iOS 10+
  • Xcode 9+

鸣谢

About

UICollectionViewLayout UICollectionViewFlowLayout 自定义布局及切换

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages