Last active
November 13, 2023 16:55
-
-
Save Myrrel/81fb944c7fade806d3e43bf4e8011343 to your computer and use it in GitHub Desktop.
Uso de gridlayout
This file contains hidden or 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
| // | |
| // ContentView.swift | |
| // cartographic-assistant | |
| // | |
| // Created by Harlock on 11/11/2023. | |
| // | |
| import SwiftUI | |
| struct ContentView: View { | |
| private var data: [Int] = Array(1...20) | |
| private var colors: [Color] = [.red,.green,.yellow, .blue] | |
| private var addaptiveColumns = [ | |
| GridItem(.adaptive(minimum: 170)) | |
| ] | |
| var body: some View { | |
| ScrollView { | |
| LazyVGrid(columns: addaptiveColumns, spacing: 20 ) { | |
| ForEach(data, id: \.self) { number in | |
| ZStack { | |
| Rectangle() | |
| .frame(width: 170, height: 170) | |
| .foregroundStyle(colors[number % 4]) | |
| .clipShape(RoundedRectangle(cornerRadius: 25.0)) | |
| Text("\(number)") | |
| .font(.system(size: 80)) | |
| .foregroundStyle(.white) | |
| } | |
| } | |
| } | |
| .padding() | |
| } | |
| } | |
| } | |
| #Preview { | |
| ContentView() | |
| } |
Author
Myrrel
commented
Nov 13, 2023

Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment