NSLayoutConstraint
Undocumented
-
Convenience method to programmatically create an
NSLayoutConstraintto size a givenUIViewto a ratio.Declaration
Swift
public static func constraintToSizeView(view:UIView, toRatio ratio:CGFloat) -> NSLayoutConstraintParameters
viewThe
UIViewthe returned constraint is configure to.ratioThe 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 givenUIViewto a fixed height, width or both.Declaration
Swift
public static func constraintsToSize(view:UIView, toWidth width:CGFloat?, andHeight height:CGFloat?) -> [NSLayoutConstraint]Parameters
viewThe
UIViewthe returned constraints are configure to.toWidthIf not
nil, anNSLayoutConstraintconfigured to size theviewto this width is created.andHeightIf not
nil, anNSLayoutConstraintconfigured to size theviewto this height is created.Return Value
An array of
NSLayoutConstraints ordered width, height. -
Convenience method to programmatically create
NSLayoutConstraints to align twoUIViews.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
viewThe first item in the created
NSLayoutConstraints.toThe second item in the created
NSLayoutConstraints.withInsetsThe
constantparameter to align the twoUIViews by. The negative values of.bottomand.rightare used to match the common use ofUIEdgeInsets. The default value isUIEdgeInsetsZero.relativeToMarginTuple 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.
View on GitHub
NSLayoutConstraint Extension Reference