2
3

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 3 years have passed since last update.

SwiftUIでList(TableView)を作る

Last updated at Posted at 2020-05-04

##リスト(tableList)を作成する
2020-05-04 11.39のイメージ.jpg

import SwiftUI

var numberArray = ["いち","に","さん","よん","ご","ろく"]
struct ContentView: View {
    var body: some View {
        List(0..<numberArray.count) {i in
            VStack {
                HStack {
                    Text("\(i + 1)")
                    Text("\(numberArray[i])")
                }
                Text("aa\(i)")
                Text("ss")
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

SwiftUIを使ってリストを作成します。
Text()などがこれまで書かれていたところに、List()を書きます。VStockを用いて鉛直方向に書き込んでいます。
セルの内容を水平方向に書くためにHStackを用いています。
リストの高さは自動で変更されます。

2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?