As you can see this layout has a pattern of cells 0, 1, 2, 0, 1, 2, 0, 1, 2 with respect to the size. I want my layout to depict 0, 1, 2, 1, 2, 1, 2, 1, 2 as the pattern with respect to size. In other words, just have the first cell to be of large size and the others should take up a size to fit the row of 2. My current code for the layout:
import UIKit
struct Layout {
private struct LayoutConstants {
static let largeGroupHeight: CGFloat = 406
static let leadingInset: CGFloat = 8
static let topInset: CGFloat = 10
static let bottomInset: CGFloat = 15
static let itemCount = 2
static let fractionalConstant: CGFloat = 1.0
static let fractionalWidthLeading: CGFloat = 0.67
static let fractionalWidthTrailing: CGFloat = 1.0
static let fractionalHeightTrailing: CGFloat = 0.3
static let fractionalContainerWidth: CGFloat = 1.2
static let groupFractionalHeight: CGFloat = 0.33
}
func layoutSection() -> NSCollectionLayoutSection {
let leadingItem = NSCollectionLayoutItem(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(LayoutConstants.fractionalWidthLeading),
heightDimension: .fractionalHeight(LayoutConstants.fractionalConstant)))
leadingItem.contentInsets = NSDirectionalEdgeInsets(top: LayoutConstants.topInset,
leading: LayoutConstants.topInset,
bottom: LayoutConstants.bottomInset,
trailing: LayoutConstants.leadingInset)
let trailingItem = NSCollectionLayoutItem(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(LayoutConstants.fractionalWidthTrailing),
heightDimension: .fractionalHeight(LayoutConstants.fractionalHeightTrailing)))
trailingItem.contentInsets = NSDirectionalEdgeInsets(top: LayoutConstants.topInset,
leading: LayoutConstants.leadingInset,
bottom: LayoutConstants.bottomInset,
trailing: LayoutConstants.leadingInset)
let trailingGroup = NSCollectionLayoutGroup.vertical(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(LayoutConstants.groupFractionalHeight),
heightDimension: .fractionalHeight(LayoutConstants.fractionalConstant)),
subitem: trailingItem,
count: LayoutConstants.itemCount)
var subitems: [NSCollectionLayoutItem] = []
subitems.append(leadingItem)
subitems.append(trailingGroup)
let containerGroup = NSCollectionLayoutGroup.horizontal(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(LayoutConstants.fractionalContainerWidth),
heightDimension: .absolute(LayoutConstants.largeGroupHeight)),
subitems: subitems)
let section = NSCollectionLayoutSection(group: containerGroup)
section.orthogonalScrollingBehavior = .continuous
return section
}
}