gpt4 book ai didi

objective-c - NSImage colorWithPatternImage : how to tile images from the top instead?

转载 作者:行者123 更新时间:2023-12-03 16:32:22 26 4
gpt4 key购买 nike

NSImage colorWithPatternImage 方法从底部平铺图像。我可以从顶部平铺它们吗?

+ (NSColor *)colorWithPatternImage:(NSImage *)image Parameters image

The 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.

这是我在 IKImageBrowserView 子类中的代码,它是我的应用程序中 NSScrollView 内的 View 。

- (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];
}

谢谢

更新:我在互联网上找到了这个解决方案。但就我而言,它不起作用,因为图像在我的 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];
}

最佳答案

这就是我的问题的解决方案。非常简单。

float yOffset = NSMaxY([self convertRect:[self frame] toView:nil]);
[[NSGraphicsContext currentContext] setPatternPhase:NSMakePoint(0,yOffset)];

关于objective-c - NSImage colorWithPatternImage : how to tile images from the top instead?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14890643/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com