Created
April 15, 2020 07:49
-
-
Save yasirmturk/0b47d18a30722902a9a4aaad05d1794a to your computer and use it in GitHub Desktop.
Remove all arranged subviews from UIStackView properly
This file contains hidden or 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
import UIKit | |
extension UIStackView { | |
@discardableResult | |
func removeAllArrangedSubviews() -> [UIView] { | |
return arrangedSubviews.reduce([UIView]()) { $0 + [removeArrangedSubViewProperly($1)] } | |
} | |
func removeArrangedSubViewProperly(_ view: UIView) -> UIView { | |
removeArrangedSubview(view) | |
NSLayoutConstraint.deactivate(view.constraints) | |
view.removeFromSuperview() | |
return view | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment