Instance Method

constraintEqualToAnchor:multiplier:

Returns a constraint that defines the anchor’s size attribute as equal to the specified anchor multiplied by the constant.

Declaration

- (NSLayoutConstraint *)constraintEqualToAnchor:(NSLayoutDimension *)anchor multiplier:(CGFloat)m;

Parameters

anchor

A dimension anchor from a UIView, NSView, or UILayoutGuide object.

m

The multiplier constant for the constraint.

Return Value

An NSLayoutConstraint object that defines the attribute represented by this layout anchor as equal to the attribute represented by the anchor parameter multiplied by the m constant.

Discussion

This method defines the relationship first attribute = m * second attribute. Where first attribute is the layout attribute represented by the anchor receiving this method call, and second attribute is the layout attribute represented by the anchor parameter.

The constraints produced by the following two examples are identical.

// Creating a constraint using NSLayoutConstraint
[NSLayoutConstraint
 constraintWithItem:self.saveButton
 attribute:NSLayoutAttributeWidth
 relatedBy:NSLayoutRelationEqual
 toItem:self.cancelButton
 attribute:NSLayoutAttributeWidth
 multiplier:2.0
 constant:0.0].active = YES;
 
// Creating the same constraint using constraintEqualToAnchor:multiplier:
[self.saveButton.widthAnchor constraintEqualToAnchor:self.cancelButton.widthAnchor multiplier:2.0].active = YES;

See Also

Building Constraints

- constraintEqualToAnchor:multiplier:constant:

Returns a constraint that defines the anchor’s size attribute as equal to the specified size attribute multiplied by a constant plus an offset.

- constraintEqualToConstant:

Returns a constraint that defines a constant size for the anchor’s size attribute.

- constraintGreaterThanOrEqualToAnchor:multiplier:

Returns a constraint that defines the anchor’s size attribute as greater than or equal to the specified anchor multiplied by the constant.

- constraintGreaterThanOrEqualToAnchor:multiplier:constant:

Returns a constraint that defines the anchor’s size attribute as greater than or equal to the specified anchor multiplied by the constant plus an offset.

- constraintGreaterThanOrEqualToConstant:

Returns a constraint that defines the minimum size for the anchor’s size attribute.

- constraintLessThanOrEqualToAnchor:multiplier:

Returns a constraint that defines the anchor’s size attribute as less than or equal to the specified anchor multiplied by the constant.

- constraintLessThanOrEqualToAnchor:multiplier:constant:

Returns a constraint that defines the anchor’s size attribute as greater than or equal to the specified anchor multiplied by the constant plus an offset.

- constraintLessThanOrEqualToConstant:

Returns a constraint that defines the maximum size for the anchor’s size attribute.