Created
October 15, 2019 21:38
-
-
Save arosenb2/fbc2e8d82475c9d65b7bf7111837311a to your computer and use it in GitHub Desktop.
SwiftUI Demo
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
import SwiftUI | |
struct ContentView: View { | |
var content: [Offer] | |
var body: some View { | |
List(content, rowContent: OfferRow.init) | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView(content: [ | |
Offer(id: 1, title: "Tropicalia", subtitle: "Hazy & Juicy Tropical IPA", imageUrl: "https://uncrate.com/p/2016/05/tropicalia-ipa.jpg"), | |
Offer(id: 2, title: "A Night on Ponce", subtitle: "India Pale Ale", imageUrl: "https://i.pinimg.com/originals/40/63/bd/4063bdc4b4b4b7ea8d948d00df5a6393.png") | |
]) | |
} | |
} |
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
import SwiftUI | |
import SDWebImageSwiftUI | |
struct Offer: Identifiable { | |
var id: Int | |
var title: String | |
var subtitle: String | |
var imageUrl: String | |
} | |
struct OfferRow: View { | |
var offer: Offer | |
var body: some View { | |
HStack(alignment: .center) { | |
WebImage(url: URL(string: offer.imageUrl)) | |
.onSuccess() | |
.resizable() | |
.scaledToFit() | |
.frame(width: 150, height: 80, alignment: .center) | |
Spacer() | |
VStack { | |
Text(offer.title) | |
.font(.headline) | |
.multilineTextAlignment(.center) | |
Text(offer.subtitle) | |
.font(.subheadline) | |
} | |
Spacer() | |
} | |
} | |
} | |
struct OfferRow_Previews: PreviewProvider { | |
static var previews: some View { | |
OfferRow(offer: | |
Offer(id: 1, title: "Tropicalia", subtitle: "Hazy & Juicy Tropical IPA", imageUrl: "https://uncrate.com/p/2016/05/tropicalia-ipa.jpg")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment