SwiftUI了解List和HStack等容器视图如何设置其子视图的样式

时间:2020-05-15 18:47:00

标签: swiftui

我目前正在学习SwiftUI,对于诸如List,Form,HStack,VStack等容器视图如何在后台修改和布局由ViewBuilder构造的视图,我感到困惑。

让我们说我想创建自己的SegmentedControl,它接受选择内容。如何从ViewBuilder返回的内容中为选定的细分和未选定的细分设置样式?

struct SegmentedControl<Content: View>: View {

private let content: () -> Content
private let selection: Binding<Int>

init(selection: Binding<Int>, @ViewBuilder content: @escaping () -> Content) {
    self.content = content
    self.selection = selection
}

var body: some View {
    content() // <- How do I proceed from here?
}
}

0 个答案:

没有答案