如何在NSView上绘制NSImage?

时间:2013-11-03 23:35:43

标签: objective-c macos drawrect nsimage

我很擅长使用Objective C绘制图像。我已经在iPhone开发中完成了图像绘制,但现在我想在Mac上完成。简而言之,下面的iPhone代码的Mac等价物是什么?

- (void) drawRect: (CGRect) rect
{
    [super drawRect:rect];

    UIImage *anotherimage = [UIImage imageNamed:@"alert.png"];
    CGPoint imagepoint = CGPointMake(10,0);
    [anotherimage drawAtPoint:imagepoint];

}

1 个答案:

答案 0 :(得分:3)

这应该有效,假设您不想要任何图像透明度和合成效果。

-(void)drawRect:(NSRect)dirtyRect
{
    [super drawRect:dirtyRect];
    NSImage *anotherImage = [NSImage imageNamed:@"alert.png"];
    [anotherImage drawAtPoint:NSMakePoint(10,0) fromRect:rectToDrawImage operation:NSCompositeCopy fraction:1.0];
}