4

When NSPathControl is used to represent path on local machine is fine!

The problem rise when I try to represent a virtual path of a remote server; in such case I have to change the icons accordingly.

The picture represents what I obtain that is not what I like.

Standard path vs. custom path

Now the question: How to change the icon of each element of the NSPathControl? Apple documentation is quite opaque about.

The only similar post is Customise NSPathControl but seems quite outdated.

Francesco Piraneo G.
  • 882
  • 3
  • 11
  • 25

1 Answers1

3

Masybe not the best, but is working.

class ViewController: NSViewController {
@IBOutlet weak var customPath: NSPathControl!

override func viewDidLoad() {
    super.viewDidLoad()

    customPath.pathItems = [
        self.pathItem(title: "root", imageName: "root"),
        self.pathItem(title: "First folder", imageName: NSImage.folderName),
        self.pathItem(title: "Second folder", imageName: NSImage.folderName)
    ]
}

func pathItem(title: String, imageName: String) -> NSPathControlItem {
    let item = NSPathControlItem()
    item.title = title
    item.image = NSImage(named: imageName)
    return item
}
}

The result

Francesco Piraneo G.
  • 882
  • 3
  • 11
  • 25