2013-10-31 52 views
0

我有2個並排排列的具有平鋪圖像背景的NSView。 當我添加約束的意見,使他們與主窗口的大小平鋪的背景圖像不再顯示,背景只是黑色。NSview中的Objective-C平鋪背景圖像

缺少什麼我在這裏?

#import "imageWellGraphics.h" 

@implementation imageWellGraphics 

- (id)initWithFrame:(NSRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     // Initialization code here. 
    } 
    return self; 
} 

- (void)drawRect:(NSRect)dirtyRect 
{ 
    CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort]; 
    CGAffineTransform affineTransform = CGContextGetCTM(context); 

    NSImage* image = [NSImage imageNamed: @"tile.png"]; 
    NSColor* imagePattern = [NSColor colorWithPatternImage: image]; 

    NSRect frame = NSInsetRect(self.bounds, 1, 1); 

    NSBezierPath* rectanglePath = [NSBezierPath bezierPathWithRect:NSMakeRect(NSMinX(frame), NSMinY(frame), NSWidth(frame), NSHeight(frame))]; 
    [NSGraphicsContext saveGraphicsState]; 
    CGContextSetPatternPhase(context, NSMakeSize(affineTransform.tx, affineTransform.ty)); 
    [imagePattern setFill]; 
    [rectanglePath fill]; 
    [NSGraphicsContext restoreGraphicsState]; 
} 

@end 

回答

0

嘛,原來的問題是我沒有正確理解/使用Images.xcassets我的背景圖像。

0

包括內部drawrect方法這一行,並檢查: -

[super drawRect:dirtyRect]; 
+0

感謝Hussain - 我錯過了,但是問題與Images.xcassets有關 – dmid