I create a UIViewRepresentable to show my PDF inside my SwiftUI app. I want to access the current page number using currentPage?.pageRef?.pageNumber. from the view in which I display the pdf. How to make PDFView Created in func makeUIView(context: UIViewRepresentableContext<PDFDisplayRepresentedView>) -> PDFView Available in the view displaying the pdf so I can access its properties to obtain page number.
import SwiftUI
import PDFKit
struct PDFDisplayView: View {
@Binding var pdfDocument : PDFDocument?
var body: some View {
PDFDisplayRepresentedView(pdfDocument: pdfDocument!)
}
}
struct PDFDisplayRepresentedView: UIViewRepresentable {
let pdfDocument: PDFDocument
init(pdfDocument: PDFDocument) {
self.pdfDocument = pdfDocument
}
func makeUIView(context: UIViewRepresentableContext<PDFDisplayRepresentedView>) -> PDFView {
return createPDFViewUsing(document: pdfDocument)
}
func updateUIView(_ pdfView: PDFView, context: UIViewRepresentableContext<PDFDisplayRepresentedView>) {
pdfView.document = pdfDocument
}
private func createPDFViewUsing(document : PDFDocument) -> PDFView {
let pdfView = PDFView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
pdfView.document = document
... set up pdfView attributes
return pdfView
}
}
view showing pdf where I want to know the page number
pseudo code
…
@State private var pdfDisplayView : PDFDisplayView?
….
var body: some View {
load the pdf into this view.
need to access the page number
pdfDisplayView
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
From the Internet I read that URLRequest sends an Accept-Encoding header by default. I also read that URLSession auto decompresses any data that’s returned compressed. However these are what the internet says. I go to the Apple docs and read the URLSession & URLRequest sections but I can’t find where does it say that it sends the Accept-Encoding headers by default or that it auto decompresses compressed data. I know it does the latter as I am able to parse compressed data and have to do nothing to decompress. Just tell me where this stuff is documented by Apple so I can read about it.
I use UIHostingController inside my UIViewController to present a SwiftUI View. I have a button in that view which I want to tap and dismiss the presented view. How do I dimiss SwiftUI views when presented in a UIHostingController...{
let vc = UIHostingController(rootView: SwiftUIView())
present(vc, animated: true, completion: nil)
}struct SwiftUIView : View {
var body: some View {
CustomButton()
}
}struct CustomButton: View {
var body: some View {
Button(action: {
self.buttonAction()
}) {
Text(buttonTitle)
}
}
func buttonAction(){
//dismiss the SwiftUIView when this button pressed
}
}