Use of NSPathControl to represent virtual path

余生颓废 提交于 2020-05-31 04:47:10

问题


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.

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:


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
}
}



来源:https://stackoverflow.com/questions/61096120/use-of-nspathcontrol-to-represent-virtual-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!