What is the best way to remove all subviews from you self.view?

前端 未结 5 577
孤城傲影
孤城傲影 2020-12-12 12:07

I was thinking maybe something like this might work:

    for (UIView* b in self.view.subviews)
    {
       [b removeFromSuperview];
    }

5条回答
  •  情深已故
    2020-12-12 12:50

    Swift:

    extension UIView {
        func removeAllSubviews() {
            for subview in subviews {
                subview.removeFromSuperview()
            }
        }
    }
    

提交回复
热议问题