【发布时间】:2018-09-04 06:57:48
【问题描述】:
我目前正在使用完全用 Swift 编码的 TreeMap 框架布局:https://github.com/yahoo/YMTreeMap
我创建了自己的 Layout 类,以便像这样自定义单元格:
import UIKit
class Layout: UICollectionViewLayout {
var rects = [CGRect]() {
didSet {
invalidateLayout()
}
}
override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
return true
}
override var collectionViewContentSize: CGSize {
return self.collectionView?.frame.size ?? .zero
}
override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
let attrs = UICollectionViewLayoutAttributes(forCellWith: indexPath)
attrs.frame = rects[indexPath.item]
return attrs
}
open override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
var index = 0
return rects.compactMap { (itemRect: CGRect) -> UICollectionViewLayoutAttributes? in
let attrs = rect.intersects(itemRect) ?
self.layoutAttributesForItem(at: IndexPath(item: index, section: 0)) : nil
index += 1
return attrs
}
}
}
但是我无法在单元格之间插入空格。我尝试了很多类似 minimumLineSpacingForSectionAt 但没有成功...
这就是我所拥有的:digitalblend.fr/today.png,这就是我们所需要的:digitalblend.fr/needed.png
有什么想法吗?提前非常感谢!
【问题讨论】:
-
您能否添加一个屏幕截图来显示您所看到的内容以及您正在寻找的结果?
-
好的,这就是我所拥有的:digitalblend.fr/today.png,这就是我们所需要的:digitalblend.fr/needed.png
-
请edit您的问题并添加这些图片。
标签: swift uicollectionview cell uicollectionviewlayout