开发者

Give NSWindow a background image

Ok, so I've created an image in Photoshop that will align with the buttons on my app, and now I'd like to make it the background image of my window so that the characters on the image will correspond to the keys on my app (a small calculator demo app I've been working on)

Basically, instead of giving buttons Text like 1,2,3,4, etc. I've made a 3x3 map with numbers of a different font just because it will look p开发者_如何学Goretty

What I'm having difficulty with now is that I can't seem to make the image the background of my window.

I created an NSImageView and I dragged the image file onto it, so I can see it now, but I can't make it the background.

Do I need to subclass the NSImageView or is there some simple method?

I'm using XCode 4, btw

Thanks!


I think you should be able to do something like:

[window setBackgroundColor:[NSColor colorWithPatternImage:[NSImage imageNamed:@"myImage.png"]]];


This is something that a layer-backed window would be good at:

[[window contentView] setWantsLayer:YES];
[[window contentView] layer].contents = myImage;

I think you stand a better chance of getting this to resize sensibly (assuming you need to) than with a pattern color.


Just to give you more options -- you should be able to [window setContentView:myImageView]. In the .xib file you'd want to add your buttons etc. as subviews of the image view.
I don't necessarily recommend this approach, but it's something to think about.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜