2013-11-21 34 views
0

我有一個UIView X這是綠色的大小(0,0,100,100)。我需要改變綠色以清除特定部分(如矩形)中該視圖的顏色(30,30,40,40)。所以只有我可以看到X背後的觀點。在ios中更改UIVIew中矩形的顏色?

在此先感謝

+0

此處添加您的代碼,你做了什麼 – Sport

+0

u能請記下我的問題的錯誤? – jailani

回答

1
Try this, I hope this would will help.. 


- (void)drawRect:(CGRect)rect { 

    CGRect greenRect = CGRectMake(0, 0, rect.size.width, rect.size.height/2.0); 
    // Fill the rectangle with grey 
    [[UIColor greenColor] setFill]; 
    UIRectFill(topRect); 

    CGRect clearRect = CGRectMake(0, rect.size.height/2.0, rect.size.width, rect.size.height/2.0); 
    [[UIColor clearColor] setFill]; 
    UIRectFill(bottomRect); 

} 
+0

謝謝你的迴應....我會試試這個,讓你知道.... – jailani

+0

嗨,我需要澄清...我會傳遞一個視圖(綠色)和矩形函數,該函數應該改變rect視圖的位置以清除顏色。在上面的代碼中,我無法得到什麼是topRect和bottomRect ...是否有可能做出UIView子類? – jailani

+0

它可能沒有子類,但不是正確的方法 – Retro