SwiftUIのTextFieldで表示するキーボードを指定する
SwiftUIのTextFieldで表示するキーボードを指定する方法です。
keyboardType
を指定することで表示するキーボードの種類を設定することができます。
This file contains 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 numberString = "" | |
var body: some View { | |
TextField("Input Number", text: $numberString) | |
.keyboardType(.decimalPad) | |
.textFieldStyle(RoundedBorderTextFieldStyle()) | |
.padding() | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |