Stretchable Images on OSX 10.9?
Today I began reading iOS Core Animation: Advanced Techniques, and one of the first topics talks about the possibility of creating a stretchable image using CALayer
contentsCenter
.
When I was reading this I thought that this could be pretty useful to me because the other day I was trying to create a stretchable button on OSX but i had to resort to the ugly and inneficient NSDrawNinePartImage
.
To my surprise, trying to test it with a simple case, by using the following code:
NSImage* image = [NSImage imageNamed:@"image"];
self.view.layer.contents = image;
self.view.layer.contentsCenter = CGRectMake(.2, .2, .5, .5);
resulted in the image being correctly rendered but there was this message in the console log:
2014-05-02 23:19:17.457 core_animation_osx_tests[3710:303] **** Misuse of NSImage and CALayer. contentsCenter is {{0.20000000000000001, 0.20000000000000001}, {0.5, 0.5}}. It should be {{0, 0}, {1, 1}}.
0 AppKit 0x00007fff92cd1af7 NSViewBackingLayerTestImageUsage + 544
1 AppKit 0x00007fff92ddc068 -[_NSViewBackingLayer setContentsCenter:] + 124
2 core_animation_osx_tests 0x00000001000011f3 -[MyViewController awakeFromNib] + 595
...
So... it seems you are misusing it by try to accomplish what it's suppose to do. Weird. From what I found, this used to work prior to Mavericks. Well, let's hope WWDC 2014 will be a step towards solving this and other OSX problems.