我正在尝试在 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);
}
但是,视图会拉伸图像以填充自身。我希望图像重复。
(the black strokes are fixed already)
另外,发生了一些奇怪的事情,因为控制台说图像的大小等于-2109897792x0
,但图像确实是32x32
! WTF?!
有人可以帮我吗?谢谢。
您可以使用以下命令创建图案颜色+[NSColor colorWithPatternImage:] http://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSColor_Class/Reference/Reference.html#//apple_ref/occ/clm/NSColor/colorWithPatternImage:然后用该“颜色”填充背景矩形。这应该可以完成你想要完成的任务。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)