SwiftUI UIViewRepresentableでPDFView その1:はじめの一歩
その1:はじめの一歩
ドキュメント:https://developer.apple.com/documentation/swiftui/uiviewrepresentable
ContentView.swift
import SwiftUI struct ContentView: View { var body: some View { PDFViewRepresentable() .padding() } }
PDFViewRepresentable.swift
import SwiftUI import PDFKit struct PDFViewRepresentable : UIViewRepresentable { typealias UIViewType = PDFView func makeUIView(context: Context) -> Self.UIViewType { let pdfView: PDFView = PDFView() if let url = Bundle.main.url(forResource: "Swift実践入門_直感的な文法と安全性を兼ね備えた言語_増補改訂第3版", withExtension: "pdf") { pdfView.document = PDFDocument(url: url) } return pdfView } func updateUIView(_ uiView: Self.UIViewType, context: Context) { } }