Ios 从Objective中的UIView中删除图形矩形
我曾经使用以下代码在UIView内部创建矩形(例如:“candleContainer”):Ios 从Objective中的UIView中删除图形矩形,ios,objective-c,uiview,Ios,Objective C,Uiview,我曾经使用以下代码在UIView内部创建矩形(例如:“candleContainer”): UIView *myBox = [[UIView alloc] initWithFrame:CGRectMake(marginX, marginY, rectWidth, rectHeight)]; [self.candleContainer addSubview:myBox]; 但是如何删除所有或每个已经绘制的矩形呢。我是通过从超级视图中删除'candleContainer'ui视图来实现的。但这不
UIView *myBox = [[UIView alloc] initWithFrame:CGRectMake(marginX, marginY, rectWidth, rectHeight)];
[self.candleContainer addSubview:myBox];
但是如何删除所有或每个已经绘制的矩形呢。我是通过从超级视图中删除'candleContainer'ui视图来实现的。但这不是真正的解决办法,对吗?。我只想删除那些矩形。我该怎么做呢?首先,您必须从self.candleContainer获取所有UIView对象!然后将其从self.candleContainer中删除
NSArray *viewsToRemove = [self.view subviews];
for (UIView *view in viewsToRemove) {
[view removeFromSuperview];
}
for (UIView *view in self.candleContainer)
{
[view removeFromSuperview];
}
或者您可以向UIView对象添加标记!然后您可以通过viewWithTag:method获取它,然后将其从self.candleContainer中删除 首先,您必须从self.candleContainer获取所有UIView对象!然后将其从self.candleContainer中删除
for (UIView *view in self.candleContainer)
{
[view removeFromSuperview];
}
或者您可以向UIView对象添加标记!然后您可以通过viewWithTag:method获取它,然后将其从self.candleContainer中删除 首先,您必须从self.candleContainer获取所有UIView对象!然后将其从self.candleContainer中删除
for (UIView *view in self.candleContainer)
{
[view removeFromSuperview];
}
或者您可以向UIView对象添加标记!然后您可以通过viewWithTag:method获取它,然后将其从self.candleContainer中删除 首先,您必须从self.candleContainer获取所有UIView对象!然后将其从self.candleContainer中删除
for (UIView *view in self.candleContainer)
{
[view removeFromSuperview];
}
或者您可以向UIView对象添加标记!然后您可以通过viewWithTag:method获取它,然后将其从self.candleContainer中删除