Я пытаюсь создать макет фида таким образом
[-------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
(я думаю).