cocoansattributedstringnstextviewnscolor

Replacing NSColor with another in NSAttributedString


I am trying to replace one color with another in NSAttributedString to enable a dark mode in a pre-Mojave-app. I have a long NSTextView which holds the string.

Is there any way to remap or mutate the color that is already set in the NSTextView, similar to what the Mojave dark mode does with NSColor.textColor? If there are multiple documents open, formatting the string by enumerating through ranges and attributes one by one is very slow.

Hints & tips using Swift or Objective-C are greatly appreciated!


Solution

  • Short Answer: Make your own "adaptable" colors.

    Long Answer

    HTH