Skip to content

Instantly share code, notes, and snippets.

@takoikatakotako
Created October 24, 2024 00:28
Show Gist options
  • Select an option

  • Save takoikatakotako/72b2526b47aaf88ee8b4b226339de258 to your computer and use it in GitHub Desktop.

Select an option

Save takoikatakotako/72b2526b47aaf88ee8b4b226339de258 to your computer and use it in GitHub Desktop.
SwiftUIのTextFieldで編集中と編集完了を検知する
import SwiftUI
struct ContentView: View {
@State var userName: String = ""
@State var onEditing: Bool = false
var body: some View {
VStack {
Text(onEditing ? "On Editing" : "Not On Editing")
TextField("Placeholder", text: $userName, onEditingChanged: { onEditing in
print("onEditingChanged: \(onEditing)")
self.onEditing = onEditing
}, onCommit: {
print("onCommit")
})
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()
}
}
}
#Preview {
ContentView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment