1

I want to show a DatePicker in SwiftUI. But the SwiftUI have no interface to customization the style of DatePicker, etc, font size ,font color . So I want to use a button to show DatePicker. After click this button , the SwiftUI DatePicker will be present.

Is there any way to implement this?

struct ContentView: View {

    @State private var date = Date()

    var body: some View {
        VStack {
            ZStack() {
                DatePicker(selection: $date, in: ...Date(), displayedComponents: .date) {
                    Text("")
                }
                .opacity(0.01)
                HStack() {
                    Text("Start Time")
                    Spacer()
                    Button("2021-08-22") {
                        print("Button was tapped")
                        // present DatePicker...
                    }
                }
            }
            .frame(height: 44)
            .padding(.horizontal, 20)
        }
    }
}

1 Answer 1

0

I find a solution as bellow:

struct ContentView: View {

    @State private var date = Date()

    var body: some View {
        VStack {
            ZStack() {
                HStack() {
                    Text("Start Time")
                    Spacer()
                    Text("2021-08-22")
                }
                DatePicker(selection: $date, in: ...Date(), displayedComponents: .date) {
                    Text("")
                }
                .opacity(0.011)
            }
            .frame(height: 44)
            .padding(.horizontal, 20)
        }
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

This doesn't appear to do what you want - it does nothing?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.