When I switch to the night appearance mode after updating the document render options the displayed page color is incorrect. How do I fix it?
Q: I am customizing backgroundFill
in -[PSPDFDocument updateRenderOptionsForType:withBlock:]
, then I switch to PSPDFAppearanceModeNight
, the page color display is incorrect. How do I fix it?
Expected | Actual |
---|---|
![]() |
![]() |
1 2 3 4 | let document: PDFDocument = ... document.updateRenderOptions(for: .page) { options in options.backgroundFill = .red } |
A: This behaviour is expected because if you already have custom document rendering options and you change the current appearance mode, then the new appearance mode’s rendering transformation will be performed on top of the current document’s rendering.
To avoid this, you would need to reset your custom rendering options before changing the appearance mode. You can do this in -[PSPDFAppearanceModeManagerDelegate appearanceManager:applyAppearanceSettingsForMode:]
. In Swift, the implementation would look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | func appearanceManager(_ manager: PDFAppearanceModeManager, applyAppearanceSettingsFor mode: PDFAppearanceMode) { // Reset custom render options only for sepia and night appearance modes. document.updateRenderOptions(for: .page) { options in var backgroundFillColor: UIColor switch mode { case .sepia, .night: // Set the default value. backgroundFillColor = .white default: backgroundFillColor = .red } options.backgroundFill = backgroundFillColor } } |