使用extension添加一个removeAllSubViews方法,遍历removeFromSuperview实现移除所有子控件。

import UIKit

extension UIView {
    
    func removeAllSubViews(){
        if self.subviews.count>0{
            self.subviews.forEach({$0.removeFromSuperview()})
        }
    }

SwiftUIKitiOS

1 条评论

  1. 游综宅
    2023-07-18 22:11
    回复

    很厉害,学习一下

添加新评论