Created
August 9, 2018 10:01
-
-
Save MaherKSantina/67fac3b1fefa6712580a1f8a5441e099 to your computer and use it in GitHub Desktop.
This file contains 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
// Step 1 | |
guard let xibItems = Bundle.main.loadNibNamed("ListingView", owner: self, options: nil), let firstXibView = xibItems[0] as? UIView else { | |
fatalError("Xib is empty or first view is not a UIView") | |
} | |
// Step 2 | |
firstXibView.translatesAutoresizingMaskIntoConstraints = false | |
// Step 3 | |
let viewConstraints = [NSLayoutAttribute.top, NSLayoutAttribute.left, NSLayoutAttribute.bottom, NSLayoutAttribute.right].map { (attribute) -> NSLayoutConstraint in | |
return NSLayoutConstraint(item: firstXibView, attribute: attribute, relatedBy: .equal, toItem: self, attribute: attribute, multiplier: 1, constant: 0) | |
} | |
// Step 4 | |
addSubview(firstXibView) | |
addConstraints(viewConstraints) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment