Skip to content

Instantly share code, notes, and snippets.

@hisoka0917
Last active July 14, 2022 11:15
Show Gist options
  • Save hisoka0917/cc3d58d5350cdcb343182df87dce309f to your computer and use it in GitHub Desktop.
Save hisoka0917/cc3d58d5350cdcb343182df87dce309f to your computer and use it in GitHub Desktop.
Reverse UIStackView Arranged Subviews in Z index
extension UIStackView {
func reverseSubviewsZIndex(setNeedsLayout: Bool = true) {
let stackedViews = self.arrangedSubviews
stackedViews.forEach {
self.removeArrangedSubview($0)
$0.removeFromSuperview()
}
stackedViews.reversed().forEach(addSubview(_:))
stackedViews.reversed().forEach(addArrangedSubview(_:))
if setNeedsLayout {
stackedViews.forEach { $0.setNeedsLayout() }
}
}
}
@VolodyaNazarkevych
Copy link

one update needed, on the line 12: stackedViews.reversed().forEach(addArrangedSubview(_:))

@hisoka0917
Copy link
Author

one update needed, on the line 12: stackedViews.reversed().forEach(addArrangedSubview(_:))

Thanks for correct. Updated it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment