Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of NSPathControl to represent virtual path

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.

like image 559
Francesco Piraneo G. Avatar asked Oct 20 '25 15:10

Francesco Piraneo G.


1 Answers

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

like image 73
Francesco Piraneo G. Avatar answered Oct 22 '25 05:10

Francesco Piraneo G.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!