Created
June 26, 2018 00:36
-
-
Save aybekckaya/4798e40259821709fd7b92f924e9c119 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
extension UIViewController { | |
func configureChildViewController(childController: UIViewController, onView: UIView?) { | |
var holderView = self.view | |
if let onView = onView { | |
holderView = onView | |
} | |
addChildViewController(childController) | |
holderView?.addSubview(childController.view) | |
constrainViewEqual(holderView: holderView!, view: childController.view) | |
childController.didMove(toParentViewController: self) | |
} | |
func constrainViewEqual(holderView: UIView, view: UIView) { | |
view.translatesAutoresizingMaskIntoConstraints = false | |
//pin 100 points from the top of the super | |
let pinTop = NSLayoutConstraint(item: view, attribute: .top, relatedBy: .equal, | |
toItem: holderView, attribute: .top, multiplier: 1.0, constant: 0) | |
let pinBottom = NSLayoutConstraint(item: view, attribute: .bottom, relatedBy: .equal, | |
toItem: holderView, attribute: .bottom, multiplier: 1.0, constant: 0) | |
let pinLeft = NSLayoutConstraint(item: view, attribute: .left, relatedBy: .equal, | |
toItem: holderView, attribute: .left, multiplier: 1.0, constant: 0) | |
let pinRight = NSLayoutConstraint(item: view, attribute: .right, relatedBy: .equal, | |
toItem: holderView, attribute: .right, multiplier: 1.0, constant: 0) | |
holderView.addConstraints([pinTop, pinBottom, pinLeft, pinRight]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment