2013-11-03 47 views
2

我很新,通常用Objective C绘制图像。我在iPhone开发中完成了图像绘制,但现在我想在Mac上完成。简而言之,以下iPhone代码的Mac等效物是什么?如何在NSView上绘制NSImage?

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

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

} 

回答

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]; 
} 
+1

你可能知道这一点,但你可能要移动的影像制作出来的**的drawRect:**它必须是干净和尽可能快。 –

+1

非常感谢。我需要做一些改变,但最终还是有效的。我添加了NSMakeRect(0,0,[anotherImage size] .width,[anotherImage size] .height) – Scsm326

+0

NSImage没有“frame”属性,或者说Xcode。 – Will