Skip to content

Instantly share code, notes, and snippets.

@tokorom
Created May 27, 2020 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tokorom/07728b5ca4989c5f7fe77c66c457d375 to your computer and use it in GitHub Desktop.
Save tokorom/07728b5ca4989c5f7fe77c66c457d375 to your computer and use it in GitHub Desktop.
let itemHeight: CGFloat = 96
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .estimated(itemHeight))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
let group = NSCollectionLayoutGroup.horizontal(layoutSize: itemSize, subitem: item, count: 1)
let section = NSCollectionLayoutSection(group: group)
section.interGroupSpacing = 16
section.contentInsets = NSDirectionalEdgeInsets(top: 20, leading: 20, bottom: 20, trailing: 20)
return UICollectionViewCompositionalLayout(section: section)
let itemHeight: CGFloat = 96
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .estimated(itemHeight))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
let group = NSCollectionLayoutGroup.vertical(layoutSize: itemSize, subitem: item, count: 1)
let section = NSCollectionLayoutSection(group: group)
section.interGroupSpacing = 16
section.contentInsets = NSDirectionalEdgeInsets(top: 20, leading: 20, bottom: 20, trailing: 20)
return UICollectionViewCompositionalLayout(section: section)
@tokorom
Copy link
Author

tokorom commented May 27, 2020

  • layout_horizontal.swift だとCellの中身のUILabelの高さに応じてCellの高さが変わる
  • layout_vertical.swift だとCellの中身のUILabelの高さに応じてCellの高さが変わらず

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment