I have following code
[[mWindow contentView] setWantsLayer:YES]; //mWindow is NSWindow object
[[mWindow contentView] layer].contents = [NSImage imageNamed:@"1.png"];
This code is working fine on 10.6 but on 10.5 mWindow
is showing nothing. Why?
NSlog(@"%@",[[mWindow contentView] layer].contents) //10.5
NSImage 0x15d030 Size={565, 305} Reps=(
NSBitmapImageRep 0x166400 Size={565, 305} ColorSpace=NSCalibratedRGBColorSpace BPS=8 BPP=24 Pixels=565x305 Alpha=NO Planar=NO Format=0
)
Because you cannot pass an NSImage
to setContents:
in 10.5. See the docs for CALayer.
contents An object that provides the contents of the layer. Animatable.
@property(retain) id contents Discussion The default value of this property is nil. When this property is nil, the layer contents are rendered to a layer-managed backing store.
You can set this property to a CGImageRef to present the contents of the image in place of the layer’s contents. (In OS X 10.6 and later, you can also set it to an NSImage object.) Assigning an image to this property replaces the layer’s own backing store with the image’s content.
Availability Available in OS X v10.5 and later. See Also @property contentsRect Related Sample Code LightTable Declared In CALayer.h