0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SwiftUIでのパーツの表示例。Array編。

0
Posted at

##まずViewの中の大まかな主要なパーツの紹介です。
VStack ヴァーティカルスタック縦方向
HStack ホリゾンタルスタック横方向
ZStack 縦横両方
List テーブル化
NavigationView ナビゲーションコントローラーの実装

とここまでは簡単に紹介しました。
それでは具体例です。

import SwiftUI

struct ContentView: View {
    @State var onViewOpen: Bool = false
    var Body: some View {
        NavigationView {
            VStack {
                NavigationLink(destination: NextView(onViewOpening: $onViewOpen), isActive: $onViewOpen){}
                Button(action: { onViewOpen = true }) {
                    Text("Next View").foregroundColor(.pink).font(.custom("serif", size: 30)
                }
            }
        }
    }
}

struct NextView: View {
    @Binding var onViewOpening: Bool
    var arr = ["Grandcross", "Love Ballad", "ZechroCross"]
    var arr2 = ["愛の星☆愛の星", "スマートウォッチ", "Gold Maker"]
    var Body: some View {
        Text("KiraKira Music EQ").foregroundColor(.green).font(.custom("serif", size: 30)
        VStack {
            List {
                ForEach(0..<arr.count) { items 
                    HStack {
                        Button(action: {}) {
                            Text("\(arr2[items]) - \(arr[items])").foregroundColor(.pink)
                        }
                    }
                }
            }
        }
    }
    
}

上記のコードは、まずNavigationViewの中に縦方向に重なるパーツをセット可能にして、NavigatinLinkで次のビューに飛ぶことを定義。

そして、つぎのビューでは、Arrayの中の配列を、0からArrayの中身の数だけ繰り返し処理し表示させるテーブルビューのような構造式を書いてみた。

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?