2013-11-21 70 views
0

這是我第一次處理自定義視圖(所以執行我的無知),所以我試圖找出這是否應該工作(或爲什麼不) 。我試圖通過執行New - > File並將父項設置爲UIView來創建自定義視圖(稱爲IAMax)。我刪除了initWithFrame並添加以下到的drawRect:爲什麼不是我的自定義視圖顯示在模擬器中

- (void)drawRect:(CGRect)rect 
{ 
    // Drawing code 
    NSLog(@"here i am"); 
    UIBezierPath *aPath = [UIBezierPath bezierPath]; 
    // Set the starting point of the shape. 
    [aPath moveToPoint:CGPointMake(100.0, 0.0)]; 
    // Draw the lines. 
    [aPath addLineToPoint:CGPointMake(200.0, 40.0)]; 
    [aPath addLineToPoint:CGPointMake(160, 140)]; 
    [aPath addLineToPoint:CGPointMake(40.0, 140)]; 
    [aPath addLineToPoint:CGPointMake(0.0, 40.0)]; 
    [aPath closePath]; 
} 

我去我的主要情節串連圖板,並拖出一個通用的UIView我的主要故事板和開關類以IAMax(和背景色切換爲綠色)。當我在模擬器中運行時,我沒有看到任何東西(但是我確實在控制檯中看到了NSLog語句)。我究竟做錯了什麼?

THX

回答

1

創建路徑後,您需要將它繪製:

[[UIColor redColor] set]; 
[aPath stroke]; 

這將繪製的路徑爲紅色。

+0

啊,非常感謝你!我以爲我在UIView中做錯了什麼 - 必須等待幾分鐘。 – timpone

相關問題