iOS13,14 CollectionView(2)Inset

2020-10-15  本文已影响0人  Jacob6666

前情提要

在 文章正在审核中... - 简书 文章的基础之上,讨论Apple又给出的两个简单的例子


正文内容

(1) Inset Items Grid

Inset Items Grid

一行代码:

item.contentInsets=NSDirectionalEdgeInsets(top:5, leading:5, bottom:5, trailing:5)

(2) Two-Column Grid

Two-Column Grid

几行代码:

// count: 2 是重点

        let group =NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitem: item, count:2)

        let spacing =CGFloat(10)

// interItemSpacing: Supplies additional spacing between items along the layout axis of the group

        group.interItemSpacing= .fixed(spacing)

        let section =NSCollectionLayoutSection(group: group)

        section.interGroupSpacing= spacing

// leading,trailing 首尾间距

        section.contentInsets=NSDirectionalEdgeInsets(top:0, leading:10, bottom:0, trailing:10)

上一篇 下一篇

猜你喜欢

热点阅读