Created
November 9, 2017 06:15
-
-
Save kishorek/eb0f12aeaba401753ed93c4d7bd3c22b to your computer and use it in GitHub Desktop.
Remove all subviews from UIView
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 UIView { | |
// Recursive remove subviews and constraints | |
func removeSubviews() { | |
self.subviews.forEach({ | |
if !($0 is UILayoutSupport) { | |
$0.removeSubviews() | |
$0.removeFromSuperview() | |
} | |
}) | |
} | |
// Recursive remove subviews and constraints | |
func removeSubviewsAndConstraints() { | |
self.subviews.forEach({ | |
$0.removeSubviewsAndConstraints() | |
$0.removeConstraints($0.constraints) | |
$0.removeFromSuperview() | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment