0

次のコードを理解するのに苦労しています:

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

背景画像をNSWindowに設定することを想定しています。だが

  1. なぜsetBackgroundColor?
  2. NSColor colorWithPatternImage本当に何をしますか?NSColorはカラーのみである必要がありますか?

私の質問はおそらく単純ですが、それは私を悩ませています。

どうも

4

1 に答える 1

1

Core Graphics has (similar to PostScript and PDF), the concept of a "pattern color". See for example Patterns in the "Quartz 2D Programming Guide":

A pattern is a sequence of drawing operations that is repeatedly painted to a graphics context. You can use patterns in the same way as you use colors.

[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.

于 2012-09-09T01:20:44.680 に答える