iOS NSLayoutConstraint Fixed Width using constraintWithItem
Found my solution. Just set the other object to nil, and the other attribute to NSLayoutAttributeNotAnAttribute (this was what I failed to think of) and use the constant parameter for the fixed width:
[self addConstraint:[NSLayoutConstraint constraintWithItem:myButton
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0
constant:200]];
Edit: since this answer still seems to get a fair share of views, I thought I'd add the Swift syntax:
self.addConstraint(NSLayoutConstraint(
item: myButton,
attribute: .width,
relatedBy: .equal,
toItem: nil,
attribute: .notAnAttribute,
multiplier: 1.0,
constant: 200))
How about using Layout Anchors?
myView.widthAnchor.constraintEqualToConstant(29).isActive = true