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?
If you’re customizing backgroundFill
in -[PSPDFDocument updateRenderOptionsForType:withBlock:]
, and then you switch to PSPDFAppearanceModeNight
, the page color display is incorrect.
Expected | Actual |
---|---|
let document: PDFDocument = ... document.updateRenderOptions(for: .page) { options in options.backgroundFill = .red }
This behavior 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’ll 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:
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 } }