Skip to content

Instantly share code, notes, and snippets.

@phynet
Last active November 3, 2017 16:20
Show Gist options
  • Select an option

  • Save phynet/9eecedf4f3b4d9aab8c245061baee774 to your computer and use it in GitHub Desktop.

Select an option

Save phynet/9eecedf4f3b4d9aab8c245061baee774 to your computer and use it in GitHub Desktop.
struct MyConstraint {
static func changeMultiplier(constraint: NSLayoutConstraint, multiplier: CGFloat) -> NSLayoutConstraint {
let newConstraint = NSLayoutConstraint(
item: constraint.firstItem,
attribute: constraint.firstAttribute,
relatedBy: constraint.relation,
toItem: constraint.secondItem,
attribute: constraint.secondAttribute,
multiplier: multiplier,
constant: constraint.constant)
newConstraint.priority = constraint.priority
NSLayoutConstraint.deactivateConstraints([constraint])
NSLayoutConstraint.activateConstraints([newConstraint])
return newConstraint
}
}
//Usage, changing multiplier to 1.2:
constraint = MyConstraint.changeMultiplier(constraint, multiplier: 1.2)
//http://stackoverflow.com/questions/19593641/can-i-change-multiplier-property-for-nslayoutconstraint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment