开发者

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()
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜