简体   繁体   中英

How to create a datepicker to the bottom in SwiftUI?

What I'm trying to approach is when user clicks on a button, a datepicker will show up at the bottom of screen. This is what I currently have but datepicker is taking the entire screen and shown as a popover.

VStack {
    Text("Birthdate").padding()
    Button(action: {
        self.showSheet = true
    }) {
        Text(startDate.toMediumString())
    }
    .sheet(isPresented: $showSheet){
        DatePicker("", selection: self.$startDate, in: ...Date(), displayedComponents: .date)
            .labelsHidden()
    }
}

This is what I want to do. 在此处输入图片说明

or this is even better if there's already a built in component I can use.

在此处输入图片说明

Sorry no chance to check. But i did something this

VStack {
Text("Birthdate").padding()
Button(action: {
    self.showSheet = true
}) {
    Text(startDate.toMediumString())
}
...

Spacer(minLength: 120)
if (self.showSheet == true){
    HStack(alignment: .bottom) {
        DatePicker("", selection: self.$startDate, in: ...Date(), displayedComponents: .date)
        .labelsHidden()
        }
    .padding(EdgeInsets.init(top: 30, leading: 40, bottom: 120, trailing: 50)).background(Color.gray.opacity(0.1))
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM