removeFromSuperview移除子视图

2018-06-04  本文已影响10人  番薯大佬

移除子视图的使用方法
方法1

for (UIView *subview in self.containerView.subviews) {
        [subview removeFromSuperview];
}

方法2

for (NSInteger i = view.subviews.count; i > 0; i--)
{
        UIView *subView = [view.subviews objectAtIndex:(i - 1)];
        [subView removeFromSuperview];
}

方法3

[self.containerView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj removeFromSuperview];
}];

方法4

[self.containerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

方法5

[self.containerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

方法6

[self.containerView.subviews performSelector:@selector(removeAllObjects)];
上一篇下一篇

猜你喜欢

热点阅读