2014-11-03 182 views
0

從UIView的卸下繪製矩形我用於創建內一個UIView的矩形(例如:「candleContainer」)通過使用以下代碼:在的ObjectiveC

UIView *myBox = [[UIView alloc] initWithFrame:CGRectMake(marginX, marginY, rectWidth, rectHeight)]; 
[self.candleContainer addSubview:myBox]; 

但如何刪除所有或每個矩形已經畫出來了。我通過從超級視圖中刪除了'candleContainer' UIView。但這不是真正的解決方案,對吧?我只想刪除那些矩形。我怎麼做?

回答

2
NSArray *viewsToRemove = [self.view subviews]; 

    for (UIView *view in viewsToRemove) { 

     [view removeFromSuperview]; 
    } 
+0

非常感謝你。 – Poles 2014-11-03 05:07:59

1

首先你要獲取所有的UIView對象從self.candleContainer的!然後從self.candleContainer中刪除它。

for (UIView *view in self.candleContainer) 
{ 
    [view removeFromSuperview]; 
} 

或者您可以添加標籤到UIView對象!然後你可以通過viewWithTag:方法獲取它,然後從self.candleContainer中移除它!