7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【SwiftUI】iOS16からTextFieldが複数行に対応してた

Posted at

はじめに

以前はTextFieldでの複数行の入力ができず、TextEditorを使用する必要がありました。
しかし、iOS16からTextFieldの複数行入力がサポートされたようなので使ってみました。

実装

import SwiftUI

struct ContentView: View {
    @State var text: String = ""
    var body: some View {
        TextField("テキストフィールド", text: $text, axis: .vertical)
            .font(.system(size: 25))
            .textFieldStyle(.roundedBorder)
            .padding(.all)
    }
}

ポイント
axis.verticalを指定することで複数行入力ができるようになります。

動画

Simulator Screen Recording - iPhone 14 - 2022-12-05 at 21.32.50.gif

おわり

SwiftUIがどんどん便利になってきますね

7
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?