Last active
May 14, 2020 14:55
-
-
Save lawreyios/eb16cfeffba6c8eb396d419c30f7edf9 to your computer and use it in GitHub Desktop.
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
struct CardView: View { | |
var title: String | |
var description: String | |
var price: Double | |
var isOnSale: Bool | |
private let cardHeight: CGFloat = 300.0 | |
private let cardWidth: CGFloat = 200.0 | |
var body: some View { | |
VStack(alignment: .leading) { | |
Spacer() | |
HStack { | |
Spacer() | |
Text(title).font(Font.system(.headline)) | |
Spacer() | |
} | |
Spacer() | |
Image(title.lowercased()).resizable().aspectRatio(contentMode: .fit).frame(width: cardWidth, height: cardWidth / 2, alignment: .center) | |
Spacer() | |
Text(description).multilineTextAlignment(.leading) | |
.lineLimit(2) | |
.frame(height: 50.0, alignment: .top) | |
.foregroundColor(Color.black) | |
.padding(.horizontal, 14.0) | |
Spacer() | |
Rectangle().frame(height: 1.0).foregroundColor(Color.gray) | |
VStack(alignment: .leading) { | |
Text("$\(String(format:"%.02f", price))") | |
.foregroundColor(Color.black) | |
Text(isOnSale ? "On Sale" : "") | |
.foregroundColor(Color.green) | |
.padding(.top, 5.0) | |
} | |
.padding(EdgeInsets(top: 10.4, leading: 14.0, bottom: 15.3, trailing: .zero)) | |
} | |
.frame(width: cardWidth, height: cardHeight) | |
.cornerRadius(4.0) | |
.background(Color.white) | |
.border(Color.gray, width: 1.0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment