Skip to content

Instantly share code, notes, and snippets.

@nekonora
Last active March 2, 2019 13:26
Show Gist options
  • Save nekonora/52473742f3d6d5359f473d387efdb3d6 to your computer and use it in GitHub Desktop.
Save nekonora/52473742f3d6d5359f473d387efdb3d6 to your computer and use it in GitHub Desktop.
UIView quick add programatically
addedView = UIView()
addSubview(addedView)
addedView.translatesAutoresizingMaskIntoConstraints = false
addConstraints([
NSLayoutConstraint(item: addedView, attribute: .centerX, relatedBy: .equal, toItem: self, attribute: .centerX, multiplier: 1.0, constant: 0),
NSLayoutConstraint(item: addedView, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: 0),
NSLayoutConstraint(item: addedView, attribute: .width, relatedBy: .equal, toItem: self, attribute: .width, multiplier: 1.0, constant: 0),
NSLayoutConstraint(item: addedView, attribute: .height, relatedBy: .equal, toItem: self, attribute: .height, multiplier: 1.0, constant: 0)
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment