Skip to content

Instantly share code, notes, and snippets.

@hirauchg
Created August 7, 2020 12:32
Show Gist options
  • Save hirauchg/8e64411e27cec94f98a3d05dedb28abb to your computer and use it in GitHub Desktop.
Save hirauchg/8e64411e27cec94f98a3d05dedb28abb to your computer and use it in GitHub Desktop.
TextFieldの実装
struct ContentView: View {
@State private var name = ""
@State private var inputText = ""
var body: some View {
VStack {
TextField("名前を入力してください", text: $inputText,
onEditingChanged: { isBegin in
if isBegin {
// 入力開始時に行いたい処理を実装する
} else {
// 入力終了時に行いたい処理を実装する
}
},
onCommit: {
// returnタップ時時に行いたい処理を実装する
self.name = self.inputText
})
.font(.title)
.padding(20)
Text(name)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment