Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created February 19, 2018 17:13
Show Gist options
  • Select an option

  • Save azamsharp/5baa99d142b878c1ba0ae3026dc663ee to your computer and use it in GitHub Desktop.

Select an option

Save azamsharp/5baa99d142b878c1ba0ae3026dc663ee to your computer and use it in GitHub Desktop.
extension UIView {
func addToParent(view :UIView) -> UIView {
view.addSubview(self)
return self
}
func bottomMargin(from view: UIView, margin :CGFloat) -> UIView {
self.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: margin).isActive = true
return self
}
func centerX(in view: UIView) -> UIView {
self.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
return self
}
func setWidth(width :CGFloat) -> UIView {
self.widthAnchor.constraint(equalToConstant: width).isActive = true
return self
}
func setHeight(height : CGFloat) -> UIView {
self.heightAnchor.constraint(equalToConstant: height).isActive = true
return self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment