Skip to content

Instantly share code, notes, and snippets.

@hadanischal
Created September 19, 2019 12:49
Show Gist options
  • Select an option

  • Save hadanischal/586a4d6fbb9a740eee98ba1d9b568c96 to your computer and use it in GitHub Desktop.

Select an option

Save hadanischal/586a4d6fbb9a740eee98ba1d9b568c96 to your computer and use it in GitHub Desktop.
//
// 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