Remove all the subviews from a UIScrollView?

前端 未结 5 1803
-上瘾入骨i
-上瘾入骨i 2021-02-02 06:08

How do I remove all of the subviews from a UIScrollview?

5条回答
  •  野性不改
    2021-02-02 06:35

    I think you just have to be careful and not to delete the scroll indicator bars.

    The code given by Adam Ko is short and elegant but it may delete the horizontal and vertical scroll indicators.

    I usually do

    for (UIView *v in scrollView.subviews) {
      if (![v isKindOfClass:[UIImageView class]]) {
        [v removeFromSuperview];
      }
    }
    

    Suposing you don't have UIImageView's added to the scroll manually.

提交回复
热议问题