不多说上图
截屏2020-03-30 16.48.10.png
这是个在同一个视图中可以选择你想显示的视图
struct ActivityView: View {
@ObservedObject var ActivityDatas : ActivityData
@State var Way = 0
var WithDrawType = ["积分折扣", "积分随机减","积分比例赠"]
var body: some View {
VStack{
Picker(selection: $Way, label: Text("")) {
ForEach(0..<WithDrawType.count) { index in
Text(self.WithDrawType[index]).tag(index)
}
}.pickerStyle(SegmentedPickerStyle()) //picker的样式
Spacer().frame(height:0)
//下面通过if else来切换你想显示的View
if WithDrawType[Way] == "积分折扣"{
Activity1(index: 0, ActivityData: ActivityDatas)
}else if WithDrawType[Way] == "积分随机减"{
Activity2(index: 0, ActivityData: ActivityDatas)
}else {
Activity3(index: 0, ActivityData: ActivityDatas)
}
}
1.定一个数组用来遍历出要显示title
2.WithDrawType[Way]这样可获得,当你点击一个选项时获取其中选项的值,这样就可以判断出你要显示的View
网友评论