Use of NSPathControl to represent virtual path

510 Views Asked by At

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.

1

There are 1 best solutions below

1
On

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