Last active
July 14, 2022 11:15
-
-
Save hisoka0917/cc3d58d5350cdcb343182df87dce309f to your computer and use it in GitHub Desktop.
Reverse UIStackView Arranged Subviews in Z index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() } | |
} | |
} | |
} |
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
one update needed, on the line 12: stackedViews.reversed().forEach(addArrangedSubview(_:))