Created
May 17, 2021 10:39
-
-
Save yousifalraheem/e62b3a7b55299040e538ac17c724d9e6 to your computer and use it in GitHub Desktop.
A TableView component for 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 SwiftUI | |
struct TableRow: Identifiable { | |
let id = UUID() | |
let cells: [AnyView] | |
} | |
struct TableView: View { | |
let headers: [String] | |
let rows: [TableRow] | |
var body: some View { | |
HStack { | |
ForEach(0..<headers.count) { columnCount in | |
if (columnCount != 0) { | |
Spacer() | |
} | |
VStack { | |
Text(headers[columnCount]) | |
.fontWeight(.bold) | |
.padding(.vertical) | |
ForEach(0..<rows.count) { rowCount in | |
rows[rowCount].cells[columnCount] | |
} | |
} | |
} | |
} | |
.padding(.horizontal) | |
} | |
} | |
struct TableView_Previews: PreviewProvider { | |
static var previews: some View { | |
TableView(headers: [], rows: []) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment