How to change color of NSPathControl

487 Views Asked by At

Please take a look at this picture:enter image description here

I know how to change the text color:

  NSPathComponentCell *cell = [_pathControl pathComponentCells].firstObject;
  cell setTextColor:[NSColor redColor];

But i'd also like to change the color of the arrows, anyone know how to implement this?

2

There are 2 best solutions below

1
On BEST ANSWER

Not supported out of the box - you need to roll your own.

Or have a look at the various 3rd party implementations out there like ITPathbar: https://www.cocoacontrols.com/controls/itpathbar

0
On

Have you tried to modify NSPathControlItem/attributedTitle:

(Limitation: macOS 10.10+)

    for pathControlItem in pathControl.pathItems {
        let range =  NSMakeRange(0, pathControlItem.attributedTitle.length)
        let attributedTitle = NSMutableAttributedString(attributedString: pathControlItem.attributedTitle)
        attributedTitle.addAttribute(.foregroundColor, value: yourColor, range: range)
        pathControlItem.attributedTitle = attributedTitle
    }

Or try to create subclass.(I didn't test it)