项目作者: iThink32

项目描述 :
A flow layout that is used to display cells with dynamic height in multiple columns
高级语言: Swift
项目地址: git://github.com/iThink32/DynamicHeightFlowLayout.git
创建时间: 2018-10-16T07:16:05Z
项目社区:https://github.com/iThink32/DynamicHeightFlowLayout

开源协议:MIT License

下载


DynamicHeightFlowLayout

What does it do ?

This project contains a simple flow layout class that allows you to fill the screen with cells of varying height in multiple
columns.

All you have to do is set the class in the flow layout section of the collectionview ,number of columns and the padding
in the IBInspector, required section insets and your good to go.

In my project i have set a top/left/bottom/right section inset of 20 and a padding of 20.

Oh ya , one more thing implement the DynamicHeightFlowLayoutDelegate as so

  1. guard let feedLayout = self.collectionView.collectionViewLayout as? DynamicHeightFlowLayout else{
  2. assertionFailure("could not get feed layout")
  3. return
  4. }
  5. feedLayout.delegate = self

and then provide the height for each item in the method

  1. func heightForItem(at indexPath: IndexPath) -> CGFloat {
  2. var height:CGFloat = 0
  3. switch indexPath.item {
  4. case 0 :
  5. height = 170
  6. case 1 :
  7. height = 150
  8. case 2 :
  9. height = 179
  10. case 3 :
  11. height = 350
  12. case 4 :
  13. height = 379
  14. case 5 :
  15. height = 300
  16. case 6 :
  17. height = 192
  18. default :
  19. height = 100
  20. }
  21. return height
  22. }

Note :

This repo also contains the drag-drop feature for UICollectionView , have a look at the implementation if needed.

Gif time :

alt text