Last active
January 18, 2020 01:46
-
-
Save ycui1/bb006bcaec842ddb7483f82a6b713bae to your computer and use it in GitHub Desktop.
This file contains 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 ContentView: View { | |
@State private var articles = Article.sampleArticles() | |
var body: some View { | |
List(articles) { article in | |
ArticleRow(article: article) | |
} | |
} | |
} | |
struct ArticleRow: View { | |
@ObservedObject var articleFetcher: ArticleFetcher | |
init(article: Article) { | |
articleFetcher = ArticleFetcher(article: article) | |
} | |
var body: some View { | |
HStack() { | |
VStack(alignment: .leading) { | |
Image(uiImage: UIImage(named: "BP_Thumbnail.png")!) | |
.resizable() | |
.frame(width: 60, height: 60, alignment: Alignment.topLeading) | |
.clipShape(Circle()) | |
.overlay(Circle().stroke(Color(white: 0.9), lineWidth: 1)) | |
Spacer() | |
} | |
VStack(alignment: HorizontalAlignment.leading, spacing: 5) { | |
Text("BetterProgramming") | |
.bold() | |
Text(articleFetcher.article.title) | |
.font(.subheadline) | |
VStack(alignment: HorizontalAlignment.leading, spacing: 0) { | |
Image(uiImage: articleFetcher.article.imageData != nil ? UIImage(data: articleFetcher.article.imageData!)!:UIImage()) | |
.resizable() | |
.aspectRatio(contentMode: ContentMode.fit) | |
.clipped() | |
.clipShape(RoundedCorners(topLeft: 10, topRight: 10)) | |
.frame(minHeight: 100, maxHeight: 220) | |
Divider() | |
Spacer(minLength: 5) | |
Text(articleFetcher.article.title) | |
.padding(.horizontal, 5) | |
.font(.system(size: 12)) | |
Text(articleFetcher.article.link ?? articleFetcher.article.id) | |
.padding(.horizontal, 5) | |
.frame(alignment:.leading) | |
.foregroundColor(Color(white: 0.5)) | |
Spacer(minLength: 5) | |
} | |
.clipped() | |
.overlay( | |
RoundedRectangle(cornerRadius: 10) | |
.stroke(Color(white:0.8), lineWidth: 1) | |
) | |
Spacer() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment