SHARE
TWEET

Untitled

a guest May 22nd, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public func anchor(_ top: NSLayoutYAxisAnchor? = nil, left: NSLayoutXAxisAnchor? = nil, bottom: NSLayoutYAxisAnchor? = nil, right: NSLayoutXAxisAnchor? = nil, topConstant: CGFloat = 0, leftConstant: CGFloat = 0, bottomConstant: CGFloat = 0, rightConstant: CGFloat = 0, widthConstant: CGFloat = 0, heightConstant: CGFloat = 0) {
  2.        translatesAutoresizingMaskIntoConstraints = false
  3.  
  4.        _ = anchorWithReturnAnchors(top, left: left, bottom: bottom, right: right, topConstant: topConstant, leftConstant: leftConstant, bottomConstant: bottomConstant, rightConstant: rightConstant, widthConstant: widthConstant, heightConstant: heightConstant)
  5.    }
  6.  
  7.    public func anchorWithReturnAnchors(_ top: NSLayoutYAxisAnchor? = nil, left: NSLayoutXAxisAnchor? = nil, bottom: NSLayoutYAxisAnchor? = nil, right: NSLayoutXAxisAnchor? = nil, topConstant: CGFloat = 0, leftConstant: CGFloat = 0, bottomConstant: CGFloat = 0, rightConstant: CGFloat = 0, widthConstant: CGFloat = 0, heightConstant: CGFloat = 0) -> [NSLayoutConstraint] {
  8.        translatesAutoresizingMaskIntoConstraints = false
  9.  
  10.        var anchors = [NSLayoutConstraint]()
  11.  
  12.        if let top = top {
  13.            anchors.append(topAnchor.constraint(equalTo: top, constant: topConstant))
  14.        }
  15.  
  16.        if let left = left {
  17.            anchors.append(leftAnchor.constraint(equalTo: left, constant: leftConstant))
  18.        }
  19.  
  20.        if let bottom = bottom {
  21.            anchors.append(bottomAnchor.constraint(equalTo: bottom, constant: -bottomConstant))
  22.        }
  23.  
  24.        if let right = right {
  25.            anchors.append(rightAnchor.constraint(equalTo: right, constant: -rightConstant))
  26.        }
  27.  
  28.        if widthConstant > 0 {
  29.            anchors.append(widthAnchor.constraint(equalToConstant: widthConstant))
  30.        }
  31.  
  32.        if heightConstant > 0 {
  33.            anchors.append(heightAnchor.constraint(equalToConstant: heightConstant))
  34.        }
  35.  
  36.        anchors.forEach({$0.isActive = true})
  37.  
  38.        return anchors
  39.    }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top