我正在尝试以这种方式创建提要布局
[-------2/3-------][---1/3---] /* 2 items - 2 thirds and 1 third */
[---1/3---][-------2/3-------] /* 2 items - 1 third and 2 thirds */
[-------2/3-------][---1/3---] /* 2 items - 2 thirds and 1 third */
[---1/3---][-------2/3-------] /* 2 items - 1 third and 2 thirds */
我能够通过做类似的事情来实现这一点
class FeedSectionController: ListSectionController {
var entry: FeedEntry!
override init() {
super.init()
inset = UIEdgeInsets(top: 0, left: 0, bottom: 15, right: 0)
}
override func numberOfItems() -> Int {
return 2
}
override func sizeForItem(at index: Int) -> CGSize {
guard let ctx = collectionContext else { return .zero }
if index == 0 {
return CGSize(width: ((ctx.containerSize.width / 3) * 2), height: 30)
} else {
return CGSize(width: (ctx.containerSize.width / 3), height: 30)
}
}
override func cellForItem(at index: Int) -> UICollectionViewCell {
let cell = UICollectionViewCell()
cell.backgroundColor = index % 2 == 0 ? .lightGray : .darkGray
return cell
}
override func didUpdate(to object: Any) {
entry = object as? FeedEntry
}
}
然而结果真的更像
[-------2/3-------][---1/3---] /* 2 items - 2 thirds and 1 third */
[-------2/3-------][---1/3---] /* 2 items - 2 thirds and 1 third */
[-------2/3-------][---1/3---] /* 2 items - 2 thirds and 1 third */
[-------2/3-------][---1/3---] /* 2 items - 2 thirds and 1 third */
这不太正确,这也意味着我每个单元格每个部分有 2 个完整的提要项目。
我想要的是每个部分都包含 X 数量的单元格,这些单元格基本上构建了一个提要项目。
但是,要做到这一点,我需要以FeedSectionController
前面概述的方式进行布局,而不是FeedSectionController
(我认为)中的项目。