使用 Form 在数组中实现 Picker 效果
struct CheckoutView: View {
@EnvironmentObject var order3: Order
static let 支付方式数组 = ["支付宝", "微信支付", "Apple Pay", "信用卡"]
@State private var paymentType = 0
var body: some View {
Form {
Section {
Picker("选择您的支付方式", selection: $paymentType) {
ForEach (0 ..< Self.支付方式数组.count) {
Text(Self.支付方式数组[$0])
}
}
}
Section {
Toggle(isOn: ) {
Label("使用会员积分", systemImage: "wallet.pass")
}
}
}
.navigationTitle("支付")
.navigationBarTitleDisplayMode(.inline)
}
}
//预览
struct CheckoutView_Previews: PreviewProvider {
static let order = Order()
static var previews: some View {
NavigationView{
CheckoutView()
.environmentObject(order)
}
}
}
网友评论