如何在 SwiftUI 中更改紧凑样式 DatePicker 弹出框位置/对齐方式?

问题描述 投票:0回答:1

有没有办法让popover中心与DatePicker对齐?

    var body: some View {
        VStack (alignment: .center){
            HStack {
                Spacer()
                Toggle("", isOn: $showDatePicker)
                    .padding()
                    .frame(width: 50, height: 30)
                Spacer()
            }
            HStack {
                if showDatePicker {
                    DatePicker("", selection: $selectedDate, displayedComponents: .hourAndMinute)
                }
            }
            .frame(width: 50, height: 30)
            Spacer()
        }
        .padding()
        .background(Color.white)
        .cornerRadius(16)
        .shadow(radius: 8)
        .frame(width: 380, height: 530)
    }

enter image description here enter image description here

ios swift iphone swiftui
1个回答
0
投票

设置

datePicker.contentHorizontalAlignment = .center
对我有用

© www.soinside.com 2019 - 2024. All rights reserved.