The NSImage colorWithPatternImage method tiles images from the bottom. Can can I tiles them from the top instead ?
+ (NSColor *)colorWithPatternImage:(NSImage *)image Parameters imageThe image to use as the pattern for the color object. The image is tiled starting at the bottom of the window. The image is not scaled.
This is my code in my subclass of IKImageBrowserView, which is the view inside NSScrollView in my app.
- (void)drawRect:(NSRect)rect
{
NSImage * backgroundImage = [NSImage imageNamed:@"deliciousLibrary.png"];
[backgroundImage setSize:NSMakeSize(459 * bgImageSize, 91 * bgImageSize)];
[[NSColor colorWithPatternImage:backgroundImage] set];
NSRectFill(rect);
[super drawRect:rect];
}
thanks
UPDATE: I've found on the internet this solution. But in my case it doesn't work because the image is not scrolling anymore in my NSScrollView.
- (void)drawRect:(NSRect)dirtyRect {
NSGraphicsContext* theContext = [NSGraphicsContext currentContext];
[theContext saveGraphicsState];
[[NSGraphicsContext currentContext] setPatternPhase:NSMakePoint(0,[self frame].size.height)];
[self.customBackgroundColour set];
NSRectFill([self bounds]);
[theContext restoreGraphicsState];
}
This is the solution to my problem. Amazingly simple.
float yOffset = NSMaxY([self convertRect:[self frame] toView:nil]);
[[NSGraphicsContext currentContext] setPatternPhase:NSMakePoint(0,yOffset)];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With