我正在调整组中NSCollectionLayoutItem
的大小。使用NSCollectionLayoutSize
和NSCollectionLayoutDimension
可以满足诸如“* 希望它是其容器宽度的一半 ”或“ 希望它是200px*”或“* 希望它的高度等于其宽度加10%”之类的要求。
但我找不到一种方法来实现我所需要的:' 我希望它的高度等于宽度加上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
}()
1条答案
按热度按时间r6hnlfcb1#
您可以自己计算分数值,添加一个常数并将其作为绝对值赋予Layout对象。