NSview中的Objective-C平铺背景图像

NSview中的Objective-C平铺背景图像,objective-c,nsview,Objective C,Nsview,我有两个并排排列的NSVIEW,它们的背景由平铺图像构成。 当我向视图添加约束,使其与主窗口一起调整大小时,平铺的背景图像不再显示,背景仅为黑色 我错过了什么 #import "imageWellGraphics.h" @implementation imageWellGraphics - (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self) { // I

我有两个并排排列的NSVIEW,它们的背景由平铺图像构成。 当我向视图添加约束,使其与主窗口一起调整大小时,平铺的背景图像不再显示,背景仅为黑色

我错过了什么

#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

drawrect
方法中包括这一行并检查:-

[super drawRect:dirtyRect];

事实证明,问题在于我没有正确理解/使用Images.xcsets作为背景图像。

谢谢Hussain-我忽略了这一点,但问题与Images.xcsets有关