示例#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);
        }
示例#2
0
        UICollectionViewLayout CreateLayout()
        {
            var itemSize = NSCollectionLayoutSize.Create(NSCollectionLayoutDimension.CreateFractionalWidth(1),
                                                         NSCollectionLayoutDimension.CreateFractionalHeight(1));
            var item = NSCollectionLayoutItem.Create(itemSize);

            var groupSize = NSCollectionLayoutSize.Create(NSCollectionLayoutDimension.CreateFractionalWidth(1),
                                                          NSCollectionLayoutDimension.CreateAbsolute(44));
            var group = NSCollectionLayoutGroup.CreateHorizontal(groupSize, item);

            var section = NSCollectionLayoutSection.Create(group);

            section.InterGroupSpacing = 5;
            section.ContentInsets     = new NSDirectionalEdgeInsets(10, 10, 10, 10);

            var sectionBackgroundDecoration = NSCollectionLayoutDecorationItem.Create(sectionBackgroundDecorationElementKind);

            sectionBackgroundDecoration.ContentInsets = new NSDirectionalEdgeInsets(5, 5, 5, 5);
            section.DecorationItems = new [] { sectionBackgroundDecoration };

            var layout = new UICollectionViewCompositionalLayout(section);

            layout.RegisterClassForDecorationView(typeof(SectionBackgroundDecorationView), new NSString(sectionBackgroundDecorationElementKind));

            return(layout);
        }
示例#3
0
        UICollectionViewLayout CreateLayout()
        {
            var itemSize = NSCollectionLayoutSize.Create(NSCollectionLayoutDimension.CreateFractionalWidth(1),
                                                         NSCollectionLayoutDimension.CreateFractionalHeight(1));
            var item = NSCollectionLayoutItem.Create(itemSize);

            var groupSize = NSCollectionLayoutSize.Create(NSCollectionLayoutDimension.CreateFractionalWidth(1),
                                                          NSCollectionLayoutDimension.CreateAbsolute(44));
            var group = NSCollectionLayoutGroup.CreateHorizontal(groupSize, item);

            var section = NSCollectionLayoutSection.Create(group);

            section.InterGroupSpacing = 5;
            section.ContentInsets     = new NSDirectionalEdgeInsets(0, 10, 0, 10);

            var headerFooterSize = NSCollectionLayoutSize.Create(NSCollectionLayoutDimension.CreateFractionalWidth(1),
                                                                 NSCollectionLayoutDimension.CreateAbsolute(44));
            var sectionHeader = NSCollectionLayoutBoundarySupplementaryItem.Create(headerFooterSize, sectionHeaderElementKind, NSRectAlignment.Top);
            var sectionFooter = NSCollectionLayoutBoundarySupplementaryItem.Create(headerFooterSize, sectionFooterElementKind, NSRectAlignment.Bottom);

            sectionHeader.PinToVisibleBounds   = true;
            sectionHeader.ZIndex               = 2;
            section.BoundarySupplementaryItems = new [] { sectionHeader, sectionFooter };

            var layout = new UICollectionViewCompositionalLayout(section);

            return(layout);
        }
示例#4
0
        //   +---------------------------------------------------+
        //   | +-----------------------------------------------+ |
        //   | |                                               | |
        //   | |                                               | |
        //   | |                       0                       | |  <- topItem
        //   | |                                               | |
        //   | |                                               | |
        //   | +-----------------------------------------------+ |
        //   | +---------------------------------+ +-----------+ |
        //   | |                                 | |           | |
        //   | |                                 | |           | |
        //   | |                                 | |     2     | |  <- trailingItem
        //   | |                                 | |           | |
        //   | |                                 | |           | |
        //   | |                                 | +-----------+ |
        //   | |               1                 |               |  <- bottomNestedGroup
        //   | |                                 | +-----------+ |
        //   | |                                 | |           | |
        //   | |                                 | |           | |
        //   | |                                 | |     3     | |  <- trailingItem
        //   | |                                 | |           | |
        //   | |                                 | |           | |
        //   | +---------------------------------+ +-----------+ |
        //   +---------------------------------------------------+
        //                leadingItem              trailingGroup
        private UICollectionViewLayout CreateLayout()
        {
            var layout = new UICollectionViewCompositionalLayout((sectionIndex, layoutEnvironment) =>
            {
                var leadingItem = NSCollectionLayoutItem.Create(
                    layoutSize: NSCollectionLayoutSize.Create(
                        width: CreateFractionalWidth(0.7f),
                        height: CreateFractionalHeight(1.0f)));
                leadingItem.ContentInsets = new NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10);

                var trailingItem = NSCollectionLayoutItem.Create(
                    layoutSize: NSCollectionLayoutSize.Create(
                        width: CreateFractionalWidth(1.0f),
                        height: CreateFractionalHeight(0.3f)));
                trailingItem.ContentInsets = new NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10);

                var trailingGroup = NSCollectionLayoutGroup.CreateVertical(
                    layoutSize: NSCollectionLayoutSize.Create(
                        width: CreateFractionalWidth(0.3f),
                        height: CreateFractionalHeight(1.0f)),
                    subitem: trailingItem,
                    count: 2);

                var bottomNestedGroup = NSCollectionLayoutGroup.CreateHorizontal(
                    layoutSize: NSCollectionLayoutSize.Create(
                        width: CreateFractionalWidth(1.0f),
                        height: CreateFractionalHeight(0.6f)),
                    subitems: new[] { leadingItem, trailingGroup });

                var topItem = NSCollectionLayoutItem.Create(
                    layoutSize: NSCollectionLayoutSize.Create(
                        width: CreateFractionalWidth(1.0f),
                        height: CreateFractionalHeight(0.3f)));
                topItem.ContentInsets = new NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10);

                var nestedGroup = NSCollectionLayoutGroup.CreateVertical(
                    layoutSize: NSCollectionLayoutSize.Create(
                        width: CreateFractionalWidth(1.0f),
                        height: CreateFractionalHeight(0.4f)),
                    subitems: new[] { topItem, bottomNestedGroup });

                var section = NSCollectionLayoutSection.Create(group: nestedGroup);

                section.OrthogonalScrollingBehavior = UICollectionLayoutSectionOrthogonalScrollingBehavior.Continuous;

                return(section);
            });

            return(layout);
        }
        private UICollectionViewLayout GetUiCollectionViewLayout()
        {
            var layoutSize = NSCollectionLayoutSize.Create(NSCollectionLayoutDimension.CreateFractionalWidth(1), NSCollectionLayoutDimension.CreateEstimated(100));
            var item       = NSCollectionLayoutItem.Create(layoutSize);
            var group      = NSCollectionLayoutGroup.CreateHorizontal(layoutSize: layoutSize, subitem: item, count: 1);
            var section    = NSCollectionLayoutSection.Create(group);

            // this is what you need for content inset
            section.ContentInsets = new NSDirectionalEdgeInsets(top: 5, leading: 5, bottom: 5, trailing: 5);

            // this is spacing between items
            section.InterGroupSpacing = 5;

            var layout = new UICollectionViewCompositionalLayout(section);

            return(layout);
        }