GREYLayoutConstraint

@interface GREYLayoutConstraint : NSObject

Modeled after NSLayoutConstraint, this class captures information related to a layout constraint: two attributes and a relation that must be satisfied between them.

  • Creates a GREYLayoutConstraint to verify a constraint attribute on an element. The relation is given by : @c attribute value = @c referenceAttribute * @c multiplier + @c constant.

    For example, with constraint relation @c kGREYLayoutRelationEqual, multiplier 2.0 and constant 10.0, the attribute values of 20.0 and 5.0 satisfy the constraint because: 20.0 = 5.0 * 2.0 + 10.0 but 30.0 and 40.0 don’t because 30.0 != 40.0 * 2.0 + 10.0.

    Declaration

    Objective-C

    + (instancetype)layoutConstraintWithAttribute:(GREYLayoutAttribute)attribute
                                        relatedBy:(GREYLayoutRelation)relation
                             toReferenceAttribute:
                                 (GREYLayoutAttribute)referenceAttribute
                                       multiplier:(CGFloat)multiplier
                                         constant:(CGFloat)constant;

    Swift

    convenience init!(attribute: Any!, relatedBy relation: Any!, toReferenceAttribute referenceAttribute: Any!, multiplier: Any!, constant: Any!)

    Parameters

    attribute

    A layout attribute to create the constraint from.

    relation

    The GREYLayoutRelation between the @c attribute and the @c referenceAttribute

    referenceAttribute

    The layout attribute whose relation is being checked with respect to @attribute.

    multiplier

    Value to multiply the @c referenceAttribute value.

    constant

    Any constant to be added to the relation being checked.

    Return Value

    A GREYLayoutConstraint instance, that constrains an element’s attribute with respect to a reference.

  • Creates a GREYLayoutConstraint that checks the position of a UI element with respect to a particular direction

    Declaration

    Objective-C

    + (instancetype)layoutConstraintForDirection:(GREYLayoutDirection)direction
                            andMinimumSeparation:(CGFloat)separation;

    Swift

    convenience init!(forDirection direction: Any!, andMinimumSeparation separation: Any!)

    Parameters

    direction

    The direction being checked against the reference element.

    separation

    The separation between an element and an edge in the given @c direction.

    Return Value

    A GREYLayoutConstraint instance that constrains an element to a particular direction.

  • @remark init is not an available initializer. Use the other initializers.

    Declaration

    Objective-C

    - (instancetype)init;

    Swift

    init!()
  • Checks if the given element satisfies the provided constraints, as shown by a reference element.

    Declaration

    Objective-C

    - (BOOL)satisfiedByElement:(id)element andReferenceElement:(id)referenceElement;

    Swift

    func satisfied(byElement element: Any!, andReferenceElement referenceElement: Any!) -> Any!

    Parameters

    element

    The element being checked for the constraints.

    referenceElement

    The reference element to check the @c element against.

    Return Value

    @c YES if the the given elements satisify the constraint, else @NO.

  • Declaration

    Objective-C

    - (NSString *)description;

    Swift

    func description() -> Any!

    Return Value

    A description of the GREYLayoutConstraint created.

  • The attribute constraint being checked.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) GREYLayoutAttribute attribute;

    Swift

    var attribute: Int32 { get set }
  • The GREYLayoutRelation between the @c attribute and the @c referenceAttribute.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) GREYLayoutRelation relation;

    Swift

    var relation: Int32 { get set }
  • The value the @c attribute is being compared to.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) GREYLayoutAttribute referenceAttribute;

    Swift

    var referenceAttribute: Int32 { get set }
  • Value to multiply the @c referenceAttribute value with.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) CGFloat multiplier;

    Swift

    var multiplier: Int32 { get set }
  • Any constant to be added to the relation being checked.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) CGFloat constant;

    Swift

    var constant: Int32 { get set }