Created
September 19, 2019 12:49
-
-
Save hadanischal/586a4d6fbb9a740eee98ba1d9b568c96 to your computer and use it in GitHub Desktop.
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
| // | |
| // UIStackView+removeAll.swift | |
| // SnackViewExample | |
| // | |
| // Created by Nischal Hada on 19/9/19. | |
| // Copyright © 2019 Nischal Hada. All rights reserved. | |
| // | |
| import UIKit | |
| extension UIStackView { | |
| func removeAllArrangedSubviews() { | |
| let removedSubviews = arrangedSubviews.reduce([]) { (allSubviews, subview) -> [UIView] in | |
| self.removeArrangedSubview(subview) | |
| return allSubviews + [subview] | |
| } | |
| // Deactivate all constraints | |
| NSLayoutConstraint.deactivate(removedSubviews.flatMap({ $0.constraints })) | |
| // Remove the views from self | |
| removedSubviews.forEach({ $0.removeFromSuperview() }) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment