2014-11-03 162 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中移除它!