I'm developing a companion app for an online magazine called The Hair Society (thehairsociety.org). Thing is, I need to retrieve the existing articles for the app to actually make sense.
I've tried many different solutions (NewsAPI, SwiftyJSON, Kanna, etc.) but none of which have worked - which is probably due to my lack of sense of where to put things.
Here's some code:
ArticlesView + ArticleRow:
Code Block // // ArticlesView.swift // Hair Society Go // // Created by Joshua Srery on 11/29/20. // import SwiftUI struct ArticlesView: View { var body: some View { NavigationView { List { ForEach(0 ..< 5) { item in NavigationLink(destination: ArticleView(title: "Replace with Title var", image: "Replace with Img var", content: "Replace with Content var", author: "Replace with Author var", date: "Replace with Date var")) { ArticleRow(image: "Replace with Img var", title: "Replace with Title var", author: "Replace with Author var", date: "Replace with Date var") } } } .navigationTitle("Articles") .toolbar(content: { Menu { Button("Date", action: {}) Button("Title", action: {}) Button("Customize…", action: {}) } label: { Label("Filter", systemImage: "line.horizontal.3.decrease.circle") } }) } } } struct ArticleRow: View { let image: String let title: String let author: String let date: String var body: some View { HStack { Image(image) .resizable() .frame(minWidth: 75, maxWidth: 100, maxHeight: 75) .cornerRadius(12) VStack(alignment: .leading, content: { Text(title) .font(.headline) Text("\(author) • \(date)") .font(.subheadline) }) } } }
That filter option will probably show in a later thread.
ArticleView:
Code Block // // ArticleView.swift // Hair Society Go // // Created by Joshua Srery on 12/16/20. // import SwiftUI struct ArticleView: View { let title: String let image: String let content: String let author: String let date: String var body: some View { ScrollView { GeometryReader { geometry in ZStack { if geometry.frame(in: .global).minY <= 0 { Image(image) .resizable() .aspectRatio(contentMode: .fill) .frame(width: geometry.size.width, height: geometry.size.height) .offset(y: geometry.frame(in: .global).minY/9) .clipped() } else { Image(image) .resizable() .aspectRatio(contentMode: .fill) .frame(width: geometry.size.width, height: geometry.size.height + geometry.frame(in: .global).minY) .clipped() .offset(y: -geometry.frame(in: .global).minY) } } } .frame(height: 400) VStack(alignment: .leading) { Text(title) .font(.largeTitle) .bold() .lineLimit(nil) .padding(.top, 10) Text("\(author) • \(date)") .foregroundColor(.gray) .padding(.top, 10) AdvertisementView(ad: "Replace with Ad var") .padding(.top) .frame(width: 350) Text(content) .lineLimit(nil) .padding(.top, 15) } .frame(minWidth: 350) .padding(.horizontal, 15) } .edgesIgnoringSafeArea(.top) } } struct AdvertisementView: View { let ad: String var body: some View { VStack { Text("Advertisement") .font(Font.system(.body).smallCaps()) .foregroundColor(.secondary) .bold() .tracking(1.0) Image(ad) .resizable() .frame(height: 37.5) Text("Advertisement") .font(Font.system(.body).smallCaps()) .foregroundColor(.secondary) .bold() .tracking(1.0) }.padding(.vertical, 3) .background(Color.white) .cornerRadius(25) .shadow(radius: 10) } }