如何调整 PDFView 以在深色模式下显示?

问题描述 投票:0回答:1

我在 SwiftUI 项目中使用 PDFView (Representable) 来显示白色背景上的黑色文本文档。

在黑暗模式下,我希望能够反转颜色,以便它们在黑色背景上显示为白色文本。

我没有看到任何方法可以更改 PDFView 中的文本颜色或页面颜色,因此想知道是否有其他方法可以让整个视图反转其颜色?

struct PDFKitView: UIViewRepresentable {
    
    let uRL: URL

    init(_ uRL: URL) {
        self.uRL = uRL
    }

    func makeUIView(context: UIViewRepresentableContext<PDFKitView>) -> PDFKitView.UIViewType {
        let pdfView = PDFView()
        pdfView.document = PDFDocument(url: self.uRL)
        pdfView.autoScales = true
        pdfView.displayMode = .singlePage
        pdfView.displayDirection = .horizontal
        pdfView.usePageViewController(true)
        pdfView.tintColor = .red
        return pdfView
    }

    func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<PDFKitView>) {

    }
}

struct ContentView: View {
        
    var body: some View {
        let url = Bundle.main.url(forResource: "example", withExtension: "pdf")!
        PDFKitView(url)
    }
}
ios swiftui pdfkit pdfview
1个回答
0
投票

只需应用 colorInvert() 视图修饰符:

PDFKitView(url)
.colorInvert()
© www.soinside.com 2019 - 2024. All rights reserved.