Skip to navigation
How to clear a swift textfield
18.07.24
```swift import SwiftUI struct ContentView: View { @State private var text: String = "" var body: some View { VStack { TextField("Enter text", text: $text) .font(.title2) .textFieldStyle(RoundedBorderTextFieldStyle()) .padding() Button("Clear Text") { text = "" // Set the text to an empty string to clear the TextField } .font(.title2) .padding() } } } ```
https://www.codespeedy.com/clear-a-textfield-on-button-tap-in-swiftui/
Reply
Anonymous
Information Epoch 1730248196
Data dominates.
Home
Notebook
Contact us