Skip to content

Instantly share code, notes, and snippets.

@Myrrel
Last active November 13, 2023 16:55
Show Gist options
  • Save Myrrel/81fb944c7fade806d3e43bf4e8011343 to your computer and use it in GitHub Desktop.
Save Myrrel/81fb944c7fade806d3e43bf4e8011343 to your computer and use it in GitHub Desktop.
Uso de gridlayout
//
// 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()
}
@Myrrel
Copy link
Author

Myrrel commented Nov 13, 2023

Screenshot 2023-11-13 at 1 54 14 PM

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