1

我正在尝试以这种样式创建一个窗口:

在此处输入图像描述

我有以下代码,但我只是得到一个背景。估计是找不到图了

var win = [[NSWindow alloc] init]
[win setFrame:NSMakeRect(0, 0, 320, 200) display:false]
[win setBackgroundColor:[NSColor colorWithPatternImage:[NSImage imageNamed:@"background.png"]]];

我正在为Sketch App 插件编写这个,所以我必须使用Cocoascript。我的插件结构看起来像

myplugin.sketchplugin/
    Contents/
        Sketch/
            app.js
            manifest.json
        Resources/
            background.png

我不确定将背景图像放在哪里或如何引用它。它必须在 manifest.json 中吗?在哪个键下?

4

1 回答 1

1

(I don't use Sketch so this is untested)

Here is an example how to load World.pdf that resides in the Resources folder.

It basically does this:

var plugin = context.plugin;// the plugin (MSPluginBundle)
var imageLayer = SketchLib.addImageLayer(group, {"name": "World", "url": [plugin urlForResourceNamed:"World.pdf"]})

So if [plugin urlForResourceNamed:"World.pdf"] does the job I suspect that

[plugin urlForResourceNamed:"background.png"] should also.

于 2015-04-12T00:17:19.863 回答