NSLayoutConstraint

Undocumented

  • Convenience method to programmatically create an NSLayoutConstraint to size a given UIView to a ratio.

    Declaration

    Swift

    public static func constraintToSizeView(view:UIView, toRatio ratio:CGFloat) -> NSLayoutConstraint

    Parameters

    view

    The UIView the returned constraint is configure to.

    ratio

    The height to width ratio expressed as a multiplier, i.e. 4:3 = 0.75.

    Return Value

    An array of NSLayoutConstraints ordered width, height.

  • Convenience method to programmatically create NSLayoutConstraints to size a given UIView to a fixed height, width or both.

    Declaration

    Swift

    public static func constraintsToSize(view:UIView, toWidth width:CGFloat?, andHeight height:CGFloat?) -> [NSLayoutConstraint]

    Parameters

    view

    The UIView the returned constraints are configure to.

    toWidth

    If not nil, an NSLayoutConstraint configured to size the view to this width is created.

    andHeight

    If not nil, an NSLayoutConstraint configured to size the view to this height is created.

    Return Value

    An array of NSLayoutConstraints ordered width, height.

  • Convenience method to programmatically create NSLayoutConstraints to align two UIViews.

    Declaration

    Swift

    public static func constraintsToAlign(view view1:UIView, to view2:UIView, withInsets insets:UIEdgeInsets = UIEdgeInsetsZero, relativeToMargin:(top:Bool, left:Bool, bottom:Bool, right:Bool) = (false, false, false, false)) -> [NSLayoutConstraint]

    Parameters

    view

    The first item in the created NSLayoutConstraints.

    to

    The second item in the created NSLayoutConstraints.

    withInsets

    The constant parameter to align the two UIViews by. The negative values of .bottom and .right are used to match the common use of UIEdgeInsets. The default value is UIEdgeInsetsZero.

    relativeToMargin

    Tuple of Bools for whether each constraint should be relative to the margin or not. Default is all false.

    Return Value

    An array of NSLayoutConstraints, ordered: top, left, bottom, right.