Instance Method

constraint(greaterThanOrEqualTo:constant:)

Returns a constraint that defines one item’s attribute as greater than or equal to another item’s attribute plus a constant offset.

Declaration

func constraint(greaterThanOrEqualTo anchor: NSLayoutAnchor<AnchorType>, constant c: CGFloat) -> NSLayoutConstraint

Parameters

anchor

A layout anchor from a UIView, NSView, or UILayoutGuide object. You must use a subclass of NSLayoutAnchor that matches the current anchor. For example, if you call this method on an NSLayoutXAxisAnchor object, this parameter must be another NSLayoutXAxisAnchor.

c

The constant offset for the constraint.

Return Value

An NSLayoutConstraint object that defines the attribute represented by this layout anchor as greater than or equal to the attribute represented by the anchor parameter plus a constant offset.

Discussion

This method defines the relationship first attribute >= second attribute + c. 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 value c, represents a constant offset. All values are measured in points; however, these values can be interpreted in different ways, depending on the type of layout anchor.

  • For NSLayoutXAxisAnchor objects, the first attribute is positioned c points after the second attribute. When using leading or trailing attributes, values increase as you move in the language’s reading direction. In English, for example, values increase as you move to the right. For left and right attributes, values always increase as you move right.

  • For NSLayoutYAxisAnchor objects, the first attribute is positioned c points below the second attribute. Values increase as you move down.

  • For NSLayoutDimension objects, the size of the first attribute is c points larger than the size of the second attribute. Values increase as items increase in size.

The constraints produced by the following two examples are identical.

// Creating a constraint using NSLayoutConstraint
 
NSLayoutConstraint(item: textField,
                   attribute: .Leading,
                   relatedBy: .GreaterThanOrEqual,
                   toItem: label,
                   attribute: .Trailing,
                   multiplier: 1.0,
                   constant: 8.0).active = true
 
// Creating the same constraint using constraintGreaterThanOrEqualToAnchor:constant:
textField.leadingAnchor.constraintGreaterThanOrEqualToAnchor(label.trailingAnchor, constant: 8.0).active = true

See Also

Building Constraints

func constraint(equalTo: NSLayoutAnchor<AnchorType>) -> NSLayoutConstraint

Returns a constraint that defines one item’s attribute as equal to another.

func constraint(equalTo: NSLayoutAnchor<AnchorType>, constant: CGFloat) -> NSLayoutConstraint

Returns a constraint that defines one item’s attribute as equal to another item’s attribute plus a constant offset.

func constraint(greaterThanOrEqualTo: NSLayoutAnchor<AnchorType>) -> NSLayoutConstraint

Returns a constraint that defines one item’s attribute as greater than or equal to another.

func constraint(lessThanOrEqualTo: NSLayoutAnchor<AnchorType>) -> NSLayoutConstraint

Returns a constraint that defines one item’s attribute as less than or equal to another.

func constraint(lessThanOrEqualTo: NSLayoutAnchor<AnchorType>, constant: CGFloat) -> NSLayoutConstraint

Returns a constraint that defines one item’s attribute as less than or equal to another item’s attribute plus a constant offset.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software