31 lines
1.1 KiB
Swift
31 lines
1.1 KiB
Swift
//
|
|
// ContainerCollectionReusableView.swift
|
|
// MVMCoreUI
|
|
//
|
|
// Created by Scott Pfeil on 4/7/20.
|
|
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
/// CollectionReusableView that can contains any other view.
|
|
public class ContainerCollectionReusableView: UICollectionReusableView {
|
|
public var view: UIView?
|
|
public var topConstraint: NSLayoutConstraint?
|
|
public var bottomConstraint: NSLayoutConstraint?
|
|
|
|
public func addAndContain(view: UIView) {
|
|
guard self.view != view else { return }
|
|
self.view?.removeFromSuperview()
|
|
view.setContentCompressionResistancePriority(.required, for: .vertical)
|
|
addSubview(view)
|
|
self.view = view
|
|
topConstraint = view.topAnchor.constraint(equalTo: topAnchor)
|
|
topConstraint?.isActive = true
|
|
bottomConstraint = bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
|
bottomConstraint?.isActive = true
|
|
rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
|
|
view.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
|
|
}
|
|
}
|