0

I have 2 NSViews arranged side by side that have backgrounds made from tiled images. When I add constraints to the views so that they resize with the main window the tiled background image no longer displays and the background is just black.

What am I missing here?

#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
dmid
  • 483
  • 4
  • 18

2 Answers2

0

Include this line inside drawrect method and check:-

[super drawRect:dirtyRect];
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
  • thanks Hussain - I was missing that, however the problem was related to Images.xcassets – dmid Nov 07 '13 at 07:42
0

Well, it turns out the problem was me not properly understanding/using Images.xcassets for my background image.

dmid
  • 483
  • 4
  • 18