Is it possible to tweak collection view cell's layoutMarginsGuide when using compositional layout?

For UITableViewCells and UICollectionViewListCells, their contentView.layoutMarginsGuide respect the colletionView's layoutMarginsGuide automatically, which can be 16 or 20 points horizontally.

This is the expected behavior.

But for regular UICollectionViewCells with a regular compositional layout, their contentView.layoutMarginsGuide are defaulted to 8 points.

I don't see where I can hook into and change the layout margins of the cells . I've looked into contentInset property and contentInsetReference property of section and item when constructing a compositional layout, but with no luck, their intentions are to change the width of the cells themselves.

Well, it turns out to be simple:

  1. enable the preservesSuperviewLayoutMargins property of the cell.
  2. enable the preservesSuperviewLayoutMargins property of the contentView of the cell as well.

They are disabled by default.

Now cell's layout margins will respect the collection view's layout margins.

Is it possible to tweak collection view cell's layoutMarginsGuide when using compositional layout?
 
 
Q