View
public extension View
Provides convienience methods for using auto layout and constraining view to the parent.
-
Creates the most basic constraints dedicated for constraining to 4 anchors of the parent veiw: top -> top, bottom -> bottom. leading -> leading, trailing -> trailing. Will attemp to use
safeAreaLayoutGuide
if possible.Declaration
Swift
@discardableResult @inline(__always) func pin(toSafeAreaOf view: View, anchor: Anchor = .all, margin: CGFloat = 0, isActive: Bool = true) -> [Anchor : LayoutConstraint]
Parameters
view
Target view to which apply constrainta. Can be parent view or view which shares the same parent. Both source and target views have to be part of the view hierarchy.
anchor
Anchor type to be used for determining which constraints to generate. Defaults to
all
and generates constaints to all 4 sides.margin
Number to be used as a constant for generated constraints. Same value applied to all generated constraints if there are multiple.
Return Value
Generated active constraints.
-
Convenience function for creating constraints while utilizing Margin enum
Declaration
Swift
@discardableResult @inline(__always) func pin(to view: View, anchor: Anchor = .all, margin: CGFloat = 0, isActive: Bool = true) -> [Anchor : LayoutConstraint]
Parameters
view
Target view to which apply constrainta. Can be parent view or view which shares the same parent. Both source and target views have to be part of the view hierarchy.
anchor
Anchor type to be used for determining which constraints to generate. Defaults to
all
and generates constaints to all 4 sides.margin
Number to be used as a constant for generated constraints. Same value applied to all generated constraints if there are multiple. Will automatically handle conversion to CGFloat.
Return Value
Generated active constraints.
-
Creates opposite constraints: source top anchor to bottom anchor of the target view.
Declaration
Swift
@discardableResult @inline(__always) func pinTopToBottom(of view: View, margin: CGFloat = 0, isActive: Bool = true) -> LayoutConstraint
Parameters
view
Target view to which apply constrainta. Can be parent view or view which shares the same parent. Both source and target views have to be part of the view hierarchy.
margin
Number of points to be used for generating margin for the view.
Return Value
Generated active constraints.
-
Creates opposite constraints: source bottom anchor to top anchor of the target view.
Declaration
Swift
@discardableResult @inline(__always) func pinBottomToTop(of view: View, margin: CGFloat = 0, isActive: Bool = true) -> LayoutConstraint
Parameters
view
Target view to which apply constrainta. Can be parent view or view which shares the same parent. Both source and target views have to be part of the view hierarchy.
margin
Number of points to be used for generating margin for the view.
Return Value
Generated active constraints.
-
Creates opposite constraints: source leading anchor to trailing anchor of the target view.
Declaration
Swift
@discardableResult @inline(__always) func pinLeadingToTrailing(of view: View, margin: CGFloat = 0, isActive: Bool = true) -> LayoutConstraint
Parameters
view
Target view to which apply constrainta. Can be parent view or view which shares the same parent. Both source and target views have to be part of the view hierarchy.
margin
Number of points to be used for generating margin for the view.
Return Value
Generated active constraints.
-
Creates opposite constraints: source trailing anchor to leading anchor of the target view.
Declaration
Swift
@discardableResult @inline(__always) func pinTrailingToLeading(of view: View, margin: CGFloat = 0, isActive: Bool = true) -> LayoutConstraint
Parameters
view
Target view to which apply constrainta. Can be parent view or view which shares the same parent. Both source and target views have to be part of the view hierarchy.
margin
Number of points to be used for generating margin for the view.
Return Value
Generated active constraints.
-
Undocumented
Declaration
Swift
@discardableResult @inline(__always) func pinToTopLeading(of view: View, margin: CGFloat = 0, isActive: Bool = true) -> [Anchor : LayoutConstraint]
-
Undocumented
Declaration
Swift
@discardableResult @inline(__always) func pinToTopLeading(ofSafeArea view: View, margin: CGFloat = 0, isActive: Bool = true) -> [Anchor : LayoutConstraint]
-
Undocumented
Declaration
Swift
@discardableResult @inline(__always) func pinToTopTrailing(of view: View, margin: CGFloat = 0, isActive: Bool = true) -> [Anchor : LayoutConstraint]
-
Undocumented
Declaration
Swift
@discardableResult @inline(__always) func pinToTopTrailing(ofSafeArea view: View, margin: CGFloat = 0, isActive: Bool = true) -> [Anchor : LayoutConstraint]
-
Undocumented
Declaration
Swift
@discardableResult @inline(__always) func pinToBottomLeading(of view: View, margin: CGFloat = 0, isActive: Bool = true) -> [Anchor : LayoutConstraint]
-
Undocumented
Declaration
Swift
@discardableResult @inline(__always) func pinToBottomLeading(ofSafeArea view: View, margin: CGFloat = 0, isActive: Bool = true) -> [Anchor : LayoutConstraint]
-
Undocumented
Declaration
Swift
@discardableResult @inline(__always) func pinToBottomTrailing(of view: View, margin: CGFloat = 0, isActive: Bool = true) -> [Anchor : LayoutConstraint]
-
Undocumented
Declaration
Swift
@discardableResult @inline(__always) func pinToBottomTrailing(ofSafeArea view: View, margin: CGFloat = 0, isActive: Bool = true) -> [Anchor : LayoutConstraint]
-
Creates constraints for width/height/size dimensions with specified size.
Declaration
Swift
@discardableResult @inline(__always) func set(_ dimension: Dimension, _ value: CGFloat) -> [LayoutConstraint]
Parameters
dimension
Dimension type to be used for determining which constraints to generate. Use
size
to generate width and height constraints simultaneously.value
Size of set dimensions.
Return Value
Generated active constraints.
-
Creates constraints for width/height/size dimensions based on another view’s width/height/size.
Declaration
Swift
@discardableResult func set(_ dimension: Dimension, to view: View) -> [LayoutConstraint]
Parameters
dimension
Dimension type to be used for determining which dimension constraints to generate. Use
size
to generate width and height constraints simultaneously..view
Parent of sibling view to use as a reference for constraints.
Return Value
Generated active constraints.
-
Creates constraints based on center x and y axis.
Declaration
Swift
@discardableResult @inline(__always) func center(to view: View, axis: Axis? = nil) -> [LayoutConstraint]
Parameters
view
Target view to which apply constrainta. Can be parent view or view which shares the same parent. Both source and target views have to be part of the view hierarchy.
axis
Axis type to be used for determining which constraints to generate. Use
all
to generate center constraints for x and y axis simultaneously.Return Value
Generated active constraints.