-
Notifications
You must be signed in to change notification settings - Fork 1
/
06-Grid.swift
40 lines (33 loc) · 1.14 KB
/
06-Grid.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
网格布局
1. 可以使用 cellSafeSize(_ kind: SKSafeSizeProviderKind, transforms: SKSafeSizeTransform) 来约束 Cell - preferredSize(limit size: CGSize, model: Model?) -> CGSize 函数中 size 的大小
2. 也可以使用 Cell - preferredSize(limit size: CGSize, model: Model?) -> CGSize 直接返回 size 来实现
*/
import SectionUI
import SwiftUI
import Combine
struct GridColorView: View {
let colors = [UIColor.red, .green, .blue, .yellow, .orange]
@State
var section = ColorCell
.wrapperToSingleTypeSection()
.setSectionStyle { section in
section.minimumLineSpacing = 1
section.minimumInteritemSpacing = 1
}
.cellSafeSize(.fraction(0.25), transforms: .height(asRatioOfWidth: 1))
var body: some View {
SKUIController {
SKCollectionViewController().reload(section)
}
.task {
section.config(models: (0...50).map({ idx in
.init(text: idx.description, color: colors[idx % colors.count])
}))
}
.ignoresSafeArea()
}
}
#Preview {
GridColorView()
}