CPCFixedAspectRatioView
public protocol CPCFixedAspectRatioView : CPCViewMeasuring
A view type that sizes instances using linear equation.
-
Tuple representing multiplier
K
and constantC
of a linear equation.Declaration
Swift
typealias AspectRatio = (multiplier: CGFloat, constant: CGFloat)
-
Returns coefficients of equation
ViewHeight = K x ViewWidth + C
to fit content.Declaration
Swift
static func aspectRatioComponents(for attributes: LayoutAttributes) -> AspectRatio?
Parameters
attributes
View-specific layout attributes to perform layout calculations.
Return Value
Multiplier K and constant C.
-
widthThatFits(height:with:)
Extension methodDeclaration
Swift
public static func widthThatFits(height: CGFloat, with attributes: LayoutAttributes) -> CGFloat
-
heightThatFits(width:with:)
Extension methodDeclaration
Swift
public static func heightThatFits(width: CGFloat, with attributes: LayoutAttributes) -> CGFloat
-
sizeThatFits(_:with:)
Extension methodDeclaration
Swift
public static func sizeThatFits(_ size: CGSize, with attributes: LayoutAttributes) -> CGSize
-
aspectRatioLayoutConstraint(for:)
Extension methodInitialize
NSLayoutConstraint
expressing dependency between view dimensions.Declaration
Swift
public func aspectRatioLayoutConstraint(for attributes: LayoutAttributes) -> NSLayoutConstraint
Parameters
attributes
Attributes for which instance aspect ratio is calculated.
Return Value
A new
NSLayoutConstraint
that ensures adequate sizing of this view.