移除一个view的所有子view
// 方法一
if (self.subviews.count > 0) {
for (UIView *subView in self.subviews) {
[subView removeFromSuperview];
}
}
// 方法二
[self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
// 方法三
[self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[obj removeFromSuperview];
}];
网友评论