I was using a Collection View and setting the Layout to self.collectionView.collectionViewLayout = setupLayout()
, where:
func setupLayout() -> UICollectionViewCompositionalLayout {
let layout = UICollectionViewCompositionalLayout { (sectionNumber, env) -> NSCollectionLayoutSection? in
let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .absolute(77)))
item.contentInsets.bottom = 5
let group = NSCollectionLayoutGroup.vertical(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1), subitems: [item])
let section = NSCollectionLayoutSection(group: group)
section.contentInsets.leading = 5
section.contentInsets.trailing = 5
return section
}
return layout
}
However, my boss wants the cell to keep having the characteristics of a TableView, with the best possible performance, containing swipe actions, for example, which are a particularity of UITableView. I saw that there is a way to initialize a compositional layout as a list, using the UICollectionViewCompositionalLayout.list
and passing a configuration as:
func setupLayout() -> UICollectionViewCompositionalLayout {
var config = UICollectionLayoutListConfiguration(appearance: .grouped)
config.trailingSwipeActionsConfigurationProvider = { indexPath in
return UISwipeActionsConfiguration(actions: [self.makeRemoveAccessContextualAction(forRowAt: indexPath)])
}
let layout = UICollectionViewCompositionalLayout.list(using: config)
return layout
}
The problem is that using it this way, I don't know how to control the margins of items and sections, like: item.contentInsets.bottom
and other contentInsets
. Is it possible to manipulate cell spacing using UICollectionViewCompositionalLayout.list
?
Update:
It was a TableView, but it needed to have different cell sizes and spacing. I suggested a CollectionView, but it needs to continue with the performance of a TableView and contain the Swipe Actions.