Created
October 24, 2024 00:28
-
-
Save takoikatakotako/72b2526b47aaf88ee8b4b226339de258 to your computer and use it in GitHub Desktop.
SwiftUIのTextFieldで編集中と編集完了を検知する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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