Removing Subitems from UIScrollView

I need to remove the subviews image from ScrollView , and I tried to remove from the array from subviews , but this is NSArray , which is immutable.

How to remove subview from scrollviews array from subviews ?

+7
source share
6 answers
  NSArray *viewsToRemove = [scrollView subviews]; for (UIView *v in viewsToRemove) [v removeFromSuperview]; 
+35
source

You can do it,

 [[scrollView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)]; 
+12
source

This will remove all UIScrollView routines, but its scroll indicators: _scrollView.showsHorizontalScrollIndicator = _scrollView.showsVerticalScrollIndicator = NO; [_scrollView.subviews makeObjectsPerformSelector: @selector (removeFromSuperview)]; _scrollView.showsHorizontalScrollIndicator = _scrollView.showsVerticalScrollIndicator = YES;

+5
source
 for (UIView *v in [scrollView subviews]) { [v removeFromSuperview]; } 
+2
source

Call -removeFromSuperview in the preview.

+1
source

Swift

 for subview in scrollView.subviews { subview.removeFromSuperview() } 
+1
source

All Articles