Created
February 23, 2021 23:46
-
-
Save karigrooms/c6c0e2f3c1cd4632406519261a024b8b to your computer and use it in GitHub Desktop.
Blog post: SwiftUI with UICollectionView - 12. Update SwiftUI Card to adapt to its container size
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 | |
protocol CardContent { | |
var imageName: String { get } | |
var title: String { get } | |
var description: String { get } | |
} | |
struct Card: View { | |
typealias Content = CardContent | |
let content: Content | |
var body: some View { | |
VStack(alignment: .leading, spacing: 8) { | |
Image(content.imageName) | |
.fitToAspectRatio(3/2) // https://gist.github.com/karigrooms/fdf435274f4403abd57b1ed533dcea53 | |
.clipShape(RoundedRectangle(cornerRadius: 4)) | |
Text(content.title) | |
.font(.headline) | |
Text(content.description) | |
.font(.body) | |
.lineLimit(1) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment