dark mode printer output

I want to print an NSView to the printer while in dark mode. For an NSTextField, I get a white background and white text, so it is unreadable.

What should I set the background and text colors to so it will print white background and black text? I currently have text color set to Text Color and background set to Text Background color, which works in light mode, but not in dark mode.

Accepted Reply

I understand the advice is to set it bthrough appearance, like in

https://developer.apple.com/documentation/appkit/nsappearancecustomization/choosing_a_specific_appearance_for_your_app


class MyContentView : NSView {

  func adoptAquaAppearance()
      self.appearance = NSAppearance(named: .aqua)
   }

}

Replies

Here is Apple advice on this :


https://developer.apple.com/documentation/macos_release_notes/macos_mojave_10_14_release_notes/appkit_release_notes_for_macos_10_14


Printing Views

When you print an NSView through an NSPrintOperation, its appearance now gets temporarily replaced by the aqua appearance during rendering. This is done to avoid printing with an inherited dark appearance. The NSView instance’s own appearance property—if it’s set—is left unaltered, so it remains possible to print views with a nonstandard appearance, if desired.

Use separate, off-screen views to print the contents of on-screen windows. To avoid altering the contents of on-screen windows, the darkAqua appearance isn't replaced when printing views that are simultaneously hosted in a window.

Thanks

The view I want to print is only being used for printing. Can I set the colors in IB? Can I specify NSAppearanceNameAqua in IB?

I would better set the appearance in code, but I do not use darkmode yet.

OK, I'll try that. I have all of my app working in dark mode now other than printing.

I tried this:

    // set the fields to compensate for dark mode
    [self.itemsTotalTextField setBackgroundColor:[NSColor colorNamed:@"whiteColor"]];
    
    [self.itemsTotalTextField setTextColor:[NSColor colorNamed:@"blackColor"]];
   


It doesn't seem to have any effect. I guess the print operation is changing the colors after I have set them.

I understand the advice is to set it bthrough appearance, like in

https://developer.apple.com/documentation/appkit/nsappearancecustomization/choosing_a_specific_appearance_for_your_app


class MyContentView : NSView {

  func adoptAquaAppearance()
      self.appearance = NSAppearance(named: .aqua)
   }

}

Thanks. That worked.

In ObjC:

[self.itemsTotalTextField setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]];


Now on to the other controls.