Created
June 7, 2024 01:25
-
-
Save takoikatakotako/928e4b3ab8f4ee471bf73846f763996d to your computer and use it in GitHub Desktop.
SwiftUIで表を作る
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 Foundation | |
struct Column: Hashable { | |
let title: String | |
let rows: [String] | |
} |
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 { | |
let pokemonData = [ | |
Column( | |
title: "No", | |
rows: ["143", "1", "7", "50", "143", "1", "7", "50", "143", "1", "7", "50", "143", "1", "7", "50", "143", "1", "7", "50", "143", "1", "7", "50"] | |
), | |
Column( | |
title: "Name", | |
rows: ["Snorlax", "Bulbasaur", "Squirtle", "Diglett", "Snorlax", "Bulbasaur", "Squirtle", "Diglett", "Snorlax", "Bulbasaur", "Squirtle", "Diglett", "Snorlax", "Bulbasaur", "Squirtle", "Diglett", "Snorlax", "Bulbasaur", "Squirtle", "Diglett", "Snorlax", "Bulbasaur", "Squirtle", "Diglett"] | |
), | |
Column( | |
title: "Category", | |
rows: ["Sleeping", "Seed", "Tiny Turtle", "Mole", "Sleeping", "Seed", "Tiny Turtle", "Mole", "Sleeping", "Seed", "Tiny Turtle", "Mole", "Sleeping", "Seed", "Tiny Turtle", "Mole", "Sleeping", "Seed", "Tiny Turtle", "Mole", "Sleeping", "Seed", "Tiny Turtle", "Mole"] | |
), | |
Column( | |
title: "Height", | |
rows: ["2.1", "0.7", "0.5", "0.2", "2.1", "0.7", "0.5", "0.2", "2.1", "0.7", "0.5", "0.2", "2.1", "0.7", "0.5", "0.2", "2.1", "0.7", "0.5", "0.2", "2.1", "0.7", "0.5", "0.2"] | |
), | |
Column( | |
title: "Weight", | |
rows: ["460.0", "6.9", "9.0", "0.8", "460.0", "6.9", "9.0", "0.8", "460.0", "6.9", "9.0", "0.8", "460.0", "6.9", "9.0", "0.8", "460.0", "6.9", "9.0", "0.8", "460.0", "6.9", "9.0", "0.8"] | |
), | |
] | |
var body: some View { | |
ScrollView { | |
VStack { | |
ScrollView(.horizontal) { | |
HStack(alignment: .top, spacing: 8) { | |
Divider() | |
ForEach(0..<pokemonData.count, id: \.self) { columnIndex in | |
VStack(alignment: .leading, spacing: 8) { | |
Divider() | |
Text(pokemonData[columnIndex].title) | |
.font(Font.system(size: 20).bold()) | |
Divider() | |
ForEach(0..<pokemonData[columnIndex].rows.count, id: \.self) { rowIndex in | |
Text(pokemonData[columnIndex].rows[rowIndex]) | |
.font(Font.system(size: 18)) | |
Divider() | |
} | |
} | |
.frame(minWidth: 80) | |
Divider() | |
} | |
} | |
.padding() | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment