有没有一种简单的方法可以在 Cocoa 的 NSCell 中组合文本和图标?
我正在尝试创建一个基于 NSOutlineView 的非常简单的选择列表小部件。但是,我很难弄清楚如何在其旁边显示图标和标签,这实际上是此类小部件(iTunes、邮件、Finder 等)的所有主流实现中的预期行为。 ..)。
到目前为止,我只是绑定了两个单独的单元格,但是当我扩展树时,图标单元格会变大,并且图标与其随附标签之间会出现间隙。我知道我可能可以通过扩展 NSCell 并提供自定义类来克服这个问题,但由于我想要实现的实际上是标准的东西,所以我不能接受没有更简单的解决方案。
老实人
I'm trying to create a very simple selection list widget based on NSOutlineView. However, I'm having a hard time figuring out how to display an icon and a label right next to it, which is really the expected behavior in all the mainstream implementations of that kind of widget out there (iTunes, mail, Finder,...).
So far I am just binding two separate cells, but then when I'm expanding the tree, the icon cell grows larger and a gap appears between the icon and its accompanying label. I know I can probably overcome this problem by extending NSCell and provide a custom class, but as what I'm trying to achieve is really the standard thing, I can't be resigned to accept that there isn't a simpler solution.
Candide
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
遗憾的是,没有一个“文本和图标”单元可供您直接使用,如您所愿,开箱即用。然而,当我在做一个项目时,我发现苹果发布了一些实现这个的示例代码,因为这是一个很常见的习惯用法。
这个可以在这里找到,具体是 ImageAndTextCell.h/m
它可以帮助教学通过阅读这个示例,您可以了解 UI 自定义,但是从头开始,只需将 ImageAndTextCell 直接放入您的项目中就可以了。
Sadly, there isn't a 'text and icon' cell that you can just use, fresh out of the box as you would like. However, when I was working on a project, I found that Apple released some sample code that implements this, since it is such a common idiom.
This can be found here, specifically ImageAndTextCell.h/m
It can help teach you about UI customization by reading through this example, but scratching that, just dropping the ImageAndTextCell straight into your project should do just fine.
您需要创建 ImageAndTextcell 来组合文本和图标..
您可以像这样创建 ImageAndTextcell 示例项目
You need to create ImageAndTextcell to combine text and icon..
you can create ImageAndTextcell like this Sample Project