若是要移除一个 UIView 的所有子视图,SDK 里没有 remove all 之类的办法。
可以用 for loop 轮回调用 – removeFromSuperview 来移除
for(UIView *view in [self.view subviews])
{
[view removesuperview];
}
若是要移动指定的视图,可以如许:
for(UIView *mylabelview in [self.view subviews])
{
if ([mylabelview isKindOfClass:[UILabel class]]) {
[mylabelview removeFromSuperview];
}
}
for (int i = 0; i < [[self.view subviews] count]; i++ )
{
[[[self.view subviews] objectAtIndex:i] removeFromSuperview];
}