2013-11-03 49 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