0
當我爲IKBrowserView設置背景時,根據視圖大小調整背景大小:是否有將它設置爲平鋪圖像的方法,重複但未調整大小?如何爲CALayer設置平鋪背景圖像?
NSImage* backgroundImage = [NSImage imageNamed:@"wood-bg2.jpg"];
CALayer* aLayer = [CALayer layer];
//aLayer.contents = backgroundImage;
CIColor *ci = [[CIColor alloc] initWithColor:[NSColor colorWithPatternImage:backgroundImage]];
CGColorSpaceRef cs = [ci colorSpace];
const CGFloat *comps = [ci components];
CGColorRef cgColor = CGColorCreate(cs, comps);
aLayer.backgroundColor = cgColor;
[itemThumbnailImageBrowserView setBackgroundLayer:aLayer];
我試過了註釋掉的代碼和當前的代碼,但都沒有工作。 感謝
感謝,由於某種原因,colorWithPatternImage行給了我這樣的警告:從兼容的指針類型 – aneuryzm 2013-02-12 12:40:31
傳遞參數1我不知道爲什麼,因爲我經過NSImage中爲你這是正確的內容類型 – aneuryzm 2013-02-12 12:40:47
啊,這是因爲backgroundColor需要一個CGColor而不是一個NSColor – aneuryzm 2013-02-12 12:44:50