I am creating an app to store documents and I would like to apply a toggle mode for Icons and List view. I've created the the List view with UICollectionViewCompositionalLayout by using
let listLayoutConfig = UICollectionLayoutListConfiguration(appearance: .insetGrouped)
let listLayout = UICollectionViewCompositionalLayout.list(using: listLayoutConfig)
collectionView.collectionViewLayout = listLayout
to configure the Layout. I also know how to configure the Icons layout.
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1/3), heightDimension: .fractionalHeight(1.0))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalWidth(1/3))
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
let section = NSCollectionLayoutSection(group: group)
let gridLayout = UICollectionViewCompositionalLayout(section: section)
collectionView.collectionViewLayout = listLayout
And I've implemented a toggle function to toggle between the 2 Layouts which calls:
collectionView.setCollectionViewLayout(getLayout(), animated: true)
My big question is how to change the item/cell layout when I call the toggle function? I would like to have the list view item with an image and a label in a vertical stack: Image|Label And in Icons view an image and a label in horizontal stack: Image Lavel
Does anyone know what's the easiest and most efficient solution for it? Thank you