I'm trying to add a youTube video on to my page and the code is in a swift file called VideoView but when I try and put VideoView(youtubeID: "id here") in my home page code it either creates another view or dosent show at all and I want it to be below what I've got the page already but also want to add more below the video. Thanks.
here's my homepage code:
struct Home: View {
var body: some View {
ScrollView {
VStack(spacing: 0) {
ZStack {
Image("")
.resizable()
.scaledToFill()
VStack(alignment: .leading) {
VStack(alignment: .leading) {
Text("")
.font(.title3)
.foregroundColor(Color.white)
.multilineTextAlignment(.leading)
.padding(.leading)
.padding(.top)
Text("")
.font(.title)
.foregroundColor(Color.white)
.multilineTextAlignment(.leading)
.padding(.leading)
.padding(.bottom)
}
.background(.opacity(0.3))
.cornerRadius(15)
}
}
VStack(alignment: .leading) {
ZStack {
Rectangle()
.frame(height: 75)
Text("")
.foregroundColor(.white)
.tracking(5)
}
VStack(alignment: .leading) {
Text("")
.font(.headline)
.padding([.top, .leading, .trailing])
.padding(.bottom, 1.0)
Text("")
.font(.body)
.padding(.horizontal)
.foregroundColor(Color.primary)
Divider()
Text("")
.font(.subheadline)
.fontWeight(.bold)
.padding([.top, .leading, .trailing])
.padding(.bottom, 1.0)
Text("")
.font(.callout)
.padding(.horizontal)
Divider()
}
}
}
}.edgesIgnoringSafeArea(.top)
}
}
here's VideoView code:
import SwiftUI
import WebKit
struct VideoView: UIViewRepresentable {
let videoID: String
func makeUIView(context: Context) -> WKWebView {
return WKWebView()
}
func updateUIView(_ uiView: WKWebView, context: Context) {
guard let youtubeURL = URL(string: "https://www.youtube.com/embed/\(videoID)") else {return}
uiView.scrollView.isScrollEnabled = false
uiView.load(URLRequest(url: youtubeURL))
}
}