Removing subviews from UIScrollView
I need to remove image subviews
from a ScrollView
and I tried removing from the array
of subviews
but that is an NSArray
which is immutable.
How 开发者_如何学Ccan a subview
be removed from the scrollviews array
of subviews
?
NSArray *viewsToRemove = [scrollView subviews];
for (UIView *v in viewsToRemove) [v removeFromSuperview];
You can do this,
[[scrollView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
This will remove all subviews of a UIScrollView but its scroll indicators: _scrollView.showsHorizontalScrollIndicator = _scrollView.showsVerticalScrollIndicator = NO; [_scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; _scrollView.showsHorizontalScrollIndicator = _scrollView.showsVerticalScrollIndicator = YES;
for (UIView *v in [scrollView subviews]) {
[v removeFromSuperview];
}
Call -removeFromSuperview on the subview.
Swift
for subview in scrollView.subviews {
subview.removeFromSuperview()
}
精彩评论