我正在尝试在我的 NSView 中绘制一个重复的背景图像,我有这个到现在:
// INIT
- (id)initWithFrame:(NSRect)frame {
if (self = [super initWithFrame:frame]) {
self.backgroundImage = [NSImage imageNamed:@"progressBackground.pdf"];
}
return self;
}
// DRAW
- (void)drawRect:(NSRect)dirtyRect {
// Draw the background
[backgroundImage drawInRect:[self bounds]
fromRect:NSMakeRect(0.0f, 0.0f, backgroundImage.size.width, backgroundImage.size.height)
operation:NSCompositeSourceAtop
fraction:1.0f];
NSLog(@"%dx%d", backgroundImage.size.width, backgroundImage.size.height);
}
但是,视图会拉伸图像以填充自身。我希望图像重复。
(黑色笔划已经固定)
此外,发生了一些奇怪的事情,因为控制台说图像的大小等于-2109897792x0
,但图像真的是32x32
!怎么回事?!
有人可以帮我吗?谢谢。