Skip to content

Instantly share code, notes, and snippets.

@MaherKSantina
Created August 9, 2018 10:01
Show Gist options
  • Save MaherKSantina/67fac3b1fefa6712580a1f8a5441e099 to your computer and use it in GitHub Desktop.
Save MaherKSantina/67fac3b1fefa6712580a1f8a5441e099 to your computer and use it in GitHub Desktop.
// 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