Skip to content

Instantly share code, notes, and snippets.

@serhii-londar
Created July 10, 2018 10:18
Show Gist options
  • Save serhii-londar/61108803fb34fe6b2352cb488cd739da to your computer and use it in GitHub Desktop.
Save serhii-londar/61108803fb34fe6b2352cb488cd739da to your computer and use it in GitHub Desktop.
import UIKit
extension UIButton {
var topConstraints: [NSLayoutConstraint]? {
return self.superview?.constraints.filter( { ($0.firstItem as? UIButton == self && $0.firstAttribute == .top) || ($0.secondItem as? UIButton == self && $0.secondAttribute == .top) })
}
var leftConstraints: [NSLayoutConstraint]? {
return self.superview?.constraints.filter( { ($0.firstItem as? UIButton == self && $0.firstAttribute == .left) || ($0.secondItem as? UIButton == self && $0.secondAttribute == .left) })
}
var rightConstraints: [NSLayoutConstraint]? {
return self.superview?.constraints.filter( { ($0.firstItem as? UIButton == self && $0.firstAttribute == .right) || ($0.secondItem as? UIButton == self && $0.secondAttribute == .right) })
}
var bottomConstraints: [NSLayoutConstraint]? {
return self.superview?.constraints.filter( { (($0.firstItem as? UIButton) == self && $0.firstAttribute == .bottom) || (($0.secondItem as? UIButton == self) && $0.secondAttribute == .bottom) })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment