UIViewController+Sweeter.swift 588 B

1234567891011121314151617
  1. //
  2. // UIViewController+Sweeter.swift
  3. //
  4. // Created by Yonat Sharon on 2019-02-08.
  5. //
  6. import UIKit
  7. public extension UIViewController {
  8. /// Sweeter: Add child view controller pinned to specific places.
  9. /// Example: addConstrainedChild(pages, constrain: .bottomMargin, .top, .left, .right)
  10. func addConstrainedChild(_ viewController: UIViewController, constrain: NSLayoutConstraint.Attribute...) {
  11. addChild(viewController)
  12. view.addConstrainedSubview(viewController.view, constrainedAttributes: constrain)
  13. viewController.didMove(toParent: self)
  14. }
  15. }