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