Learn Courses My Dashboard

Adding Done button to TextField numberPad using SwiftUI

Can you please show us how to do it for iOS 14

@rahmonali

Are you using SwiftUI or UIKit?

I am using SwiftUI and my target for app is iOS 14

In that case the SwiftUI code provided in the earlier posts, ie:

struct ContentView: View {
    @State private var administeredFluids = ""
    @FocusState var isInputActive: Bool

    var body: some View {
        NavigationView {
            VStack {
                TextField("Fluids already given (mL): ", text: $administeredFluids)
                    .textFieldStyle(.roundedBorder)
                    .focused($isInputActive)
                    .toolbar {
                        ToolbarItemGroup(placement: .keyboard) {
                            Spacer()

                            Button("Done") {
                                isInputActive = false
                            }
                        }
                }
            }
            .padding(.horizontal)
        }
    }
}

wont work because @FocusState and ToolBarItemGroup(placement: .keyboard) is only available from iOS15 and later.

Sorry.

1 Like

@rahmonali

I have split your question into a thread on it’s own.

Is there a reason that you want to target as early as iOS 14?

1 Like

Well actually I am creating an app for my company and they told me to target iOS 14. It would be better if you help me with this issue.

I don’t know the answer. Remember that I am not Chris Ching so I don’t know how to solve every problem people present here. I can only help with what I know.

I got it. Thank you so much!