Overlapping Views in UIStackView

后端 未结 7 1687
时光说笑
时光说笑 2020-12-14 17:24

I have an horizontal stack view that I added arranged sub views to it (7 cells). Each one of the cells in the stack has a circular badge that exceeds the view boundaries (ne

7条回答
  •  鱼传尺愫
    2020-12-14 17:33

    Below is a simple extension on UIStackView to reverse the z-index of the UIStackView's subviews and optionally require layout:

    extension UIStackView {
    
      func reverseSubviewsZIndex(setNeedsLayout: Bool = true) {
        let stackedViews = self.arrangedSubviews
    
        stackedViews.forEach {
          self.removeArrangedSubview($0)
          $0.removeFromSuperview()
        }
    
        stackedViews.reversed().forEach(addSubview(_:))
        stackedViews.forEach(addArrangedSubview(_:))
    
        if setNeedsLayout {
          stackedViews.forEach { $0.setNeedsLayout() }
        }
      }
    
    }
    

提交回复
热议问题