iOS
[iOS][SwiftUI] TextField
teamnova
2023. 1. 14. 12:00
728x90
TextField란
레이블과 값에 대한 바인딩이 있는 TextField를 작성할 수 있습니다. 값이 문자열인 경우, TextField는 사용자가 입력하거나 편집할 때 값을 계속 업데이트합니다.String타입이 아닌 경우, return값을 누르는 등 사용자가 편집을 커밋할 때 값을 업데이트합니다.
키보드 종류 바꾸는 법
만약 사용자가 TextField를 탭 했을 때 사용 가능한 키패드 종류를 바꿔주는 방법도 있습니다.
struct ContentView: View {
@State var Text = ""
var body: some View {
Form {
Section {
TextField("Amount", text: $Text)
.keyboardType(.decimalPad) //키패드 종류(숫자)
}
Section {
Text("$ \(Text)")
}
}
}
}
https://developer.apple.com/documentation/uikit/uikeyboardtype ( 키패드 종류 )
Apple Developer Documentation
developer.apple.com