Header alignment with UICollectionLayoutListConfiguration in grouped appearance

Hello,

I am using compositional layout to create list of objects.

I have followed the official documentation and tried the provided sample here: https://developer.apple.com/documentation/uikit/views_and_controls/collection_views/implementing_modern_collection_views

However, I have seen something weird with the ListAppearancesViewController.

When I use the sample as provided (initial appearance is set to "plain"), if I change the appearance to "grouped" by clicking on the bar item, the height of the header is displayed according to the label:

But if I change the initial appearance in the code to "grouped" or "insetGrouped", the height is higher:

Which one is the correct behavior? Having this space or not?

But with this space, the accessory is not vertically aligned with the header, which is weird. How to solve that?

Thanks for the help!

Nghia

Hello,

After some search, I see that we change the top and bottom margin for the text to center it:

let margin = 11.0
configuration.directionalLayoutMargins.bottom = margin
configuration.directionalLayoutMargins.top = margin

It's initially at 17 (top) and 6 (bottom).

Header alignment with UICollectionLayoutListConfiguration in grouped appearance
 
 
Q