NSLayoutConstraint
Undocumented
-
Convenience method to programmatically create an
NSLayoutConstraint
to size a givenUIView
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
NSLayoutConstraint
s ordered width, height. -
Convenience method to programmatically create
NSLayoutConstraint
s to size a givenUIView
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
, anNSLayoutConstraint
configured to size theview
to this width is created.andHeight
If not
nil
, anNSLayoutConstraint
configured to size theview
to this height is created.Return Value
An array of
NSLayoutConstraint
s ordered width, height. -
Convenience method to programmatically create
NSLayoutConstraint
s to align twoUIView
s.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
NSLayoutConstraint
s.to
The second item in the created
NSLayoutConstraint
s.withInsets
The
constant
parameter to align the twoUIView
s by. The negative values of.bottom
and.right
are used to match the common use ofUIEdgeInsets
. The default value isUIEdgeInsetsZero
.relativeToMargin
Tuple of
Bool
s for whether each constraint should be relative to the margin or not. Default is all false.Return Value
An array of
NSLayoutConstraint
s, ordered: top, left, bottom, right.