示例#1
0
        private UICollectionViewLayout CreateLayout()
        {
            var layout = new UICollectionViewCompositionalLayout((sectionIndex, layoutEnvironment) =>
            {
                var sectionKind = EnumExtensions.FindByValue <Section>((byte)sectionIndex);
                var columns     = sectionKind.ColumnCount(layoutEnvironment.Container.EffectiveContentSize.Width);

                var itemSize = NSCollectionLayoutSize.Create(
                    width: CreateFractionalWidth(1.0f),
                    height: CreateFractionalHeight(1.0f));
                var item           = NSCollectionLayoutItem.Create(itemSize);
                item.ContentInsets = new NSDirectionalEdgeInsets(top: 2, leading: 2, bottom: 2, trailing: 2);

                var groupHeight = layoutEnvironment.TraitCollection.VerticalSizeClass == UIUserInterfaceSizeClass.Compact
                    ? CreateAbsolute(44)
                    : CreateFractionalWidth(0.2f);

                var groupSize = NSCollectionLayoutSize.Create(
                    width: CreateFractionalWidth(1.0f),
                    height: groupHeight);
                var group = NSCollectionLayoutGroup.CreateHorizontal(layoutSize: groupSize, subitem: item, count: columns);

                var section           = NSCollectionLayoutSection.Create(group);
                section.ContentInsets = new NSDirectionalEdgeInsets(top: 20, leading: 20, bottom: 20, trailing: 20);
                return(section);
            });

            return(layout);
        }