使用NSPathControl表示虚拟路径 [英] Use of NSPathControl to represent virtual path

查看:175
本文介绍了使用NSPathControl表示虚拟路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用NSPathControl表示本地计算机上的路径时,就可以了!

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.

现在的问题是:如何更改NSPathControl的每个元素的图标?苹果的文档非常模糊.

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

唯一类似的帖子是自定义NSPathControl ,但看起来已经过时了.

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

推荐答案

Masybe并不是最好的,但是正在工作.

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

这篇关于使用NSPathControl表示虚拟路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆