I’ve having trouble to understand that following piece of code :
[window setBackgroundColor:[NSColor colorWithPatternImage:[NSImage imageNamed:@"myImage.png"]]];
It’s suppose to set a background image to a NSWindow. But
- Why setBackgroundColor ?
- What does
NSColor colorWithPatternImagereally do ? Should a NSColor only be a color ?
My question a probably simple but it’s disturbing me.
Thx
Core Graphics has (similar to PostScript and PDF), the concept of a “pattern color”. See for example Patterns in the “Quartz 2D Programming Guide”:
[NSColor colorWithPatternImage:image]creates a pattern that draws the image repeatedly. So in your case, if the image has the same size as the window, it is drawn just once. But if the image is smaller than the window, it will be repeatedly drawn in x- and y-direction to fill the window background.