有没有办法让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)
}
设置
datePicker.contentHorizontalAlignment = .center
对我有用