Swift frameモディファイアを使ってTextFieldの大きさを変えるサンプル
環境
Swift version 5.2.3 (swift-5.2.3-RELEASE)
構文
TextField(“",text: $editText)
.frame(height : /*高さ*/, width : /*横幅*/)
TextFieldにframeモディファイアを指定します。
frameモディファイアの引数「height」に高さ、引数「width」に横幅を指定します。
使用例
struct ContentView: View {
@State var editText = ""
var body: some View {
VStack {
TextField("Input Text",text: $editText)
.padding()
.frame(height : 100.0, width : 200.0)
.overlay(
RoundedRectangle(cornerRadius: 5)
.stroke(Color.blue, lineWidth: 1)
)
.padding()
}
}
}