我正在调整NSCollectionLayoutItem
其组中的一个。使用NSCollectionLayoutSize
并且NSCollectionLayoutDimension
我可以实现诸如'<em>我希望它是其容器宽度的一半'或'我希望它是 200px ' 或'<em>我希望它的高度与它的宽度相同的要求加10%'。
但我找不到实现我需要的方法:'<em>我希望它的高度与它的宽度相同,再加上 28px'。
这有可能吗?
代码:
private lazy var myFancyLayout: NSCollectionLayoutSection = {
let itemSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0),
heightDimension: .fractionalWidth(1.0)
)
let item = NSCollectionLayoutItem(layoutSize: itemSize)
// Make the group with width equal to half container width and with height 110% its width
let groupSize_fractional = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(0.50),
heightDimension: .fractionalWidth(0.50 * 1.1)
)
// Make the group with width equal to 100px and with height 110% its width
let groupSize_absoulte = NSCollectionLayoutSize(
widthDimension: .absolute(100),
heightDimension: .absolute(100 * 1.1)
)
// Make the group with width equal to half container width and with height same as its width plus 20px
let groupSize_mixed_impossibleToImplement = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(0.50),
heightDimension: .fractionalWidth(0.50) // + 20px ??
)
let group = NSCollectionLayoutGroup.horizontal(
layoutSize: groupSize_fractional, // or groupSize_absoulte or groupSize_mixed_impossibleToImplement
subitem: item,
count: 1
)
let section = NSCollectionLayoutSection(group: group)
// ... further configuration
return section
}()