Skip to content

Instantly share code, notes, and snippets.

@shirishbankar1
Last active April 12, 2021 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shirishbankar1/f428345d1bdd9e59240a47920ca9e4f6 to your computer and use it in GitHub Desktop.
Save shirishbankar1/f428345d1bdd9e59240a47920ca9e4f6 to your computer and use it in GitHub Desktop.
//
// ContentView.swift
// SwiftUIDemo1
//
// Created by Shirish Bankar on 16/03/21.
//
import SwiftUI
struct ContentView: View {
let avengers : [Hero] = [
Hero( name: "Iron Man", description: "Genius, billionare, play***, philanthropist", color: .red, images: ["iron_1","iron_2","iron_3","iron_4","iron_5","iron_6"]),
Hero( name: "Captain America", description: "Avengers Assemble!", color: .blue, images: ["captain_1","captain_2","captain_3","captain_4","captain_5"]),
Hero( name: "Wanda", description: "Everybody's afraid of something", color: .blue, images: ["wanda_1","wanda_2","wanda_3","wanda_4"]),
Hero( name: "Vision", description: "Our very strength invites challenge, challenges incite conflicts, and conflicts breeds catastrophe", color: .blue, images: ["vision_1","vision_2","vision_3","vision_4"]),
Hero( name: "Hulk", description: "Thats my secret, I am always angry", color: .blue, images: ["hulk_1","hulk_2","hulk_3","hulk_4"])
]
let images = ["iron_1","iron_2","iron_3","iron_4","iron_5","iron_6"]
private var gridItemLayout = [GridItem(.flexible())]
var body: some View
{
List(avengers) { hero in
GeometryReader { geometry in
VStack(alignment : .leading){
Text(hero.name)
.font(.title)
.padding(.leading)
.offset(x: 0, y: 0)
.frame(width: geometry.size.width , height: 25, alignment: .leading)
Text(hero.description)
.font(.subheadline)
.padding([ .leading])
.frame(width: geometry.size.width , height: 40, alignment: .leading)
ScrollView(.horizontal,showsIndicators: false) {
LazyHGrid(rows: gridItemLayout, spacing: 20) {
ForEach(hero.images, id: \.self) { imageName in
Image(imageName)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 100, height: 100, alignment: .center)
.cornerRadius(8)
}
}
}
.offset(x: 0, y: 0)
.frame(minWidth: 0, idealWidth: /*@START_MENU_TOKEN@*/100/*@END_MENU_TOKEN@*/, maxWidth: /*@START_MENU_TOKEN@*/.infinity/*@END_MENU_TOKEN@*/, minHeight: /*@START_MENU_TOKEN@*/0/*@END_MENU_TOKEN@*/, idealHeight: /*@START_MENU_TOKEN@*/100/*@END_MENU_TOKEN@*/, maxHeight: 100, alignment: .center)
}
}
}.environment(\.defaultMinListRowHeight, 200)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct Hero: Identifiable {
var id = UUID()
var name : String
var description: String
var color: Color
var images : [String]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment