ScrollableContainerView

Updated
Dec 12, 2021 4:38 AM
Created
Dec 12, 2021 4:38 AM
Tags
Attributes

final class ScrollableContainerView: UIScrollView {

  public func setContent(_ view: UIView) {

    subviews.forEach {
      $0.removeFromSuperview()
    }

    addSubview(view)

    view.translatesAutoresizingMaskIntoConstraints = false

    NSLayoutConstraint.activate([
      view.leftAnchor.constraint(equalTo: frameLayoutGuide.leftAnchor),
      view.rightAnchor.constraint(equalTo: frameLayoutGuide.rightAnchor),
      view.leftAnchor.constraint(equalTo: contentLayoutGuide.leftAnchor),
      view.rightAnchor.constraint(equalTo: contentLayoutGuide.rightAnchor),
      view.topAnchor.constraint(equalTo: contentLayoutGuide.topAnchor),
      view.bottomAnchor.constraint(equalTo: contentLayoutGuide.bottomAnchor),
    ])

  }

}

image