2012-07-16 22 views
0

標題對於我想要執行的操作相當具體。我有一個自定義視圖,並在該視圖中繪製了一些元素。如何以編程方式更改自動調整屬性?我環顧四周,無法找到任何有助於我的案例。目標c在自定義視圖中更改NSRect的自動調整

目標C:

- (void)drawRect:(NSRect)HTMLContent { 
    NSGraphicsContext* gc = [NSGraphicsContext currentContext]; 
    [gc saveGraphicsState]; 
    int height = [[NSScreen mainScreen] frame].size.height; 
    int screenwidth = [[NSScreen mainScreen] frame].size.width; 
    int emailInnerContentWidth = screenwidth - 510; 

    // Horizontal Line 
    [[NSColor colorWithCalibratedRed:.8 green:.82 blue:.83 alpha:1] setFill]; 
    NSBezierPath* drawingPath = [NSBezierPath bezierPathWithRect:NSMakeRect(337, 570, emailInnerContentWidth, 2)]; 
    [drawingPath fill]; 

    // Social Icon 
    NSRect outrect = NSMakeRect(355, 585, 58, 58); 
    [[NSColor lightGrayColor] setStroke]; 
    [[NSColor colorWithPatternImage:[NSImage imageNamed:@"NoSocialIcon.png"]] setFill]; 
    NSBezierPath* outcirclePath = [NSBezierPath bezierPath]; 
    [outcirclePath appendBezierPathWithOvalInRect: outrect]; 
    [[NSColor lightGrayColor] setStroke];[[NSImage imageNamed:@"NoSocialIcon.png"] drawInRect:outrect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1]; 
    [outcirclePath stroke]; 

    // Restore graphics state 
    [gc restoreGraphicsState]; 
} 

我要設置這些2個形狀不被改變窗口的底部會受到影響。當窗口的頂部改變高度時,我希望它改變。我看過蘋果文檔,似乎沒有任何工作。在此先感謝

回答

1

因此,針對兩個形狀:

[shape setAutoresizingMask:NSViewNotSizable | NSViewMaxXMargin | NSViewMinYMargin]; 
+0

這立即崩潰我的應用程序。還給出了一個警告'多個方法命名'setAutosizingMask:'...' – jtorraca 2012-07-16 00:31:37

+0

如果「形狀」是一個UIView子類,上面應該編譯和工作。顯然不是。一旦你確定了你的觀點,你可以使用上面的內容來獲得正確的 – 2012-07-16 13:35:04

+0

哦,謝謝。我沒有意識到它必須是一個子類。完美的作品! – jtorraca 2012-07-16 16:17:20