【问题标题】:How to invert icons when selected in NSOutlineView or NSTableView在 NSOutlineView 或 NSTableView 中选择时如何反转图标
【发布时间】:2014-07-15 13:24:35
【问题描述】:

在我的应用程序中,我使用NSOutlineViewNSTableView 中的图标(通过NSImageCell)。

The icons look fine, but when the row is selected the icons aren't visible very well:

在 Finder 中,例如,选定的图标会变成白色负片:

如何在我的 App 中实现这种效果?

【问题讨论】:

    标签: objective-c cocoa nstableview nsoutlineview


    【解决方案1】:

    如果您希望 Cocoa 自动为您的图像着色,您需要确保将 isTemplate 设置为 YES。在https://developer.apple.com/library/Mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSImage_Class/Reference/Reference.html#//apple_ref/occ/instm/NSImage/setTemplate 阅读更多相关信息:

    但是,由于您希望图像在正常状态下为全彩色,因此不适合使用模板图像,因为它会将图像染成灰色,或者根据上下文的需要。现在您必须选择以下两个选项之一:

    1. 提供一个替代图像,它是正常图像的白色版本,并根据所选状态切换进/出 细胞

    2. 通过自己为正常图像着色并按上述方式切换来生成备用图像

    【讨论】:

    • 我声明 Render As 设置为Template Image(即使用.xcassets),但结果看起来仍然相同。我还直接在NSImage 上尝试了setTemplate,结果相同。
    • 在 isTemplate 中使用黑色图标
    猜你喜欢
    • 1970-01-01
    • 2015-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-13
    • 1970-01-01
    • 2011-12-03
    • 2015-07-03
    相关资源
    最近更新 更多