Commit 09cdb27c by Daniel Dahan

development: updated SwitchControl to Switch

parent 412c2ca7
......@@ -31,642 +31,603 @@
import UIKit
public class Layout {
/// Parent UIView context.
internal weak var parent: UIView?
/// Parent UIView context.
internal weak var parent: UIView?
/// Child UIView context.
internal weak var child: UIView?
/**
/**
An initializer that takes in a parent context.
- Parameter parent: An optional parent UIView.
*/
public init(parent: UIView?) {
self.parent = parent
}
/**
public init(parent: UIView?) {
self.parent = parent
}
/**
An initializer that takes in a parent context and child context.
- Parameter parent: An optional parent UIView.
- Parameter child: An optional child UIView.
*/
public init(parent: UIView?, child: UIView?) {
public init(parent: UIView?, child: UIView?) {
self.parent = parent
self.child = child
}
/**
/**
Prints a debug message when the parent context is not available.
- Parameter function: A String representation of the function that
caused the issue.
- Returns: The current Layout instance.
*/
internal func debugParentNotAvailableMessage(function: String = #function) -> Layout {
debugPrint("[Material Layout Error: Parent view context is not available for \(function).")
return self
}
/**
internal func debugParentNotAvailableMessage(function: String = #function) -> Layout {
debugPrint("[Material Layout Error: Parent view context is not available for \(function).")
return self
}
/**
Prints a debug message when the child context is not available.
- Parameter function: A String representation of the function that
caused the issue.
- Returns: The current Layout instance.
*/
internal func debugChildNotAvailableMessage(function: String = #function) -> Layout {
debugPrint("[Material Layout Error: Child view context is not available for \(function).")
return self
}
/**
internal func debugChildNotAvailableMessage(function: String = #function) -> Layout {
debugPrint("[Material Layout Error: Child view context is not available for \(function).")
return self
}
/**
Sets the width of a view.
- Parameter child: A child UIView to layout.
- Parameter width: A CGFloat value.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func width(_ child: UIView, width: CGFloat, multiplier: CGFloat = 1) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
public func width(_ child: UIView, width: CGFloat) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.width(parent: v, child: child, width: width, multiplier: multiplier)
self.child = child
Layout.width(parent: v, child: child, width: width)
return self
}
}
/**
/**
Sets the width of a view assuming a child context view.
- Parameter width: A CGFloat value.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func width(_ width: CGFloat, multiplier: CGFloat = 1) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return self.width(v, width: width, multiplier: multiplier)
public func width(_ width: CGFloat) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return self.width(v, width: width)
}
/**
/**
Sets the height of a view.
- Parameter child: A child UIView to layout.
- Parameter height: A CGFloat value.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func height(_ child: UIView, height: CGFloat, multiplier: CGFloat = 1) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
public func height(_ child: UIView, height: CGFloat) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.height(parent: v, child: child, height: height, multiplier: multiplier)
return self
}
/**
self.child = child
Layout.height(parent: v, child: child, height: height)
return self
}
/**
Sets the height of a view assuming a child context view.
- Parameter height: A CGFloat value.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func height(_ height: CGFloat, multiplier: CGFloat = 1) -> Layout {
public func height(_ height: CGFloat) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
return debugChildNotAvailableMessage()
}
return self.height(v, height: height, multiplier: multiplier)
return self.height(v, height: height)
}
/**
/**
Sets the width and height of a view.
- Parameter child: A child UIView to layout.
- Parameter size: A CGSize value.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func size(_ child: UIView, size: CGSize, multiplier: CGFloat = 1) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
public func size(_ child: UIView, size: CGSize) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.size(parent: v, child: child, size: size, multiplier: multiplier)
self.child = child
Layout.size(parent: v, child: child, size: size)
return self
}
}
/**
/**
Sets the width and height of a view assuming a child context view.
- Parameter size: A CGSize value.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func size(_ size: CGSize = CGSize.zero, multiplier: CGFloat = 1) -> Layout {
public func size(_ size: CGSize = CGSize.zero) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
return debugChildNotAvailableMessage()
}
return self.size(v, size: size, multiplier: multiplier)
return self.size(v, size: size)
}
/**
/**
A collection of children views are horizontally stretched with optional left,
right padding and interim interimSpace.
- Parameter children: An Array UIView to layout.
- Parameter left: A CGFloat value for padding the left side.
- Parameter right: A CGFloat value for padding the right side.
- Parameter interimSpace: A CGFloat value for interim interimSpace.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func horizontally(_ children: [UIView], left: CGFloat = 0, right: CGFloat = 0, interimSpace: InterimSpace = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
public func horizontally(_ children: [UIView], left: CGFloat = 0, right: CGFloat = 0, interimSpace: InterimSpace = 0) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
Layout.horizontally(parent: v, children: children, left: left, right: right, interimSpace: interimSpace, multiplier: multiplier)
Layout.horizontally(parent: v, children: children, left: left, right: right, interimSpace: interimSpace)
return self
}
/**
}
/**
A collection of children views are vertically stretched with optional top,
bottom padding and interim interimSpace.
- Parameter children: An Array UIView to layout.
- Parameter top: A CGFloat value for padding the top side.
- Parameter bottom: A CGFloat value for padding the bottom side.
- Parameter interimSpace: A CGFloat value for interim interimSpace.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func vertically(_ children: [UIView], top: CGFloat = 0, bottom: CGFloat = 0, interimSpace: InterimSpace = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
public func vertically(_ children: [UIView], top: CGFloat = 0, bottom: CGFloat = 0, interimSpace: InterimSpace = 0) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
Layout.vertically(parent: v, children: children, top: top, bottom: bottom, interimSpace: interimSpace, multiplier: multiplier)
Layout.vertically(parent: v, children: children, top: top, bottom: bottom, interimSpace: interimSpace)
return self
}
/**
}
/**
A child view is horizontally stretched with optional left and right padding.
- Parameter child: A child UIView to layout.
- Parameter left: A CGFloat value for padding the left side.
- Parameter right: A CGFloat value for padding the right side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func horizontally(_ child: UIView, left: CGFloat = 0, right: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
public func horizontally(_ child: UIView, left: CGFloat = 0, right: CGFloat = 0) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.horizontally(parent: v, child: child, left: left, right: right, multiplier: multiplier)
self.child = child
Layout.horizontally(parent: v, child: child, left: left, right: right)
return self
}
}
/**
/**
A child view is horizontally stretched with optional left and right padding.
- Parameter left: A CGFloat value for padding the left side.
- Parameter right: A CGFloat value for padding the right side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func horizontally(left: CGFloat = 0, right: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
public func horizontally(left: CGFloat = 0, right: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return horizontally(v, left: left, right: right, multiplier: multiplier)
return horizontally(v, left: left, right: right)
}
/**
/**
A child view is vertically stretched with optional left and right padding.
- Parameter child: A child UIView to layout.
- Parameter top: A CGFloat value for padding the top side.
- Parameter bottom: A CGFloat value for padding the bottom side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func vertically(_ child: UIView, top: CGFloat = 0, bottom: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
public func vertically(_ child: UIView, top: CGFloat = 0, bottom: CGFloat = 0) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.vertically(parent: v, child: child, top: top, bottom: bottom, multiplier: multiplier)
self.child = child
Layout.vertically(parent: v, child: child, top: top, bottom: bottom)
return self
}
}
/**
/**
A child view is vertically stretched with optional left and right padding.
- Parameter top: A CGFloat value for padding the top side.
- Parameter bottom: A CGFloat value for padding the bottom side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func vertically(top: CGFloat = 0, bottom: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
public func vertically(top: CGFloat = 0, bottom: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return vertically(v, top: top, bottom: bottom, multiplier: multiplier)
return vertically(v, top: top, bottom: bottom)
}
/**
/**
A child view is vertically and horizontally stretched with optional top, left, bottom and right padding.
- Parameter child: A child UIView to layout.
- Parameter top: A CGFloat value for padding the top side.
- Parameter left: A CGFloat value for padding the left side.
- Parameter bottom: A CGFloat value for padding the bottom side.
- Parameter right: A CGFloat value for padding the right side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func edges(_ child: UIView, top: CGFloat = 0, left: CGFloat = 0, bottom: CGFloat = 0, right: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.edges(parent: v, child: child, top: top, left: left, bottom: bottom, right: right, multiplier: multiplier)
return self
}
/**
- Returns: The current Layout instance.
*/
public func edges(_ child: UIView, top: CGFloat = 0, left: CGFloat = 0, bottom: CGFloat = 0, right: CGFloat = 0) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.edges(parent: v, child: child, top: top, left: left, bottom: bottom, right: right)
return self
}
/**
A child view is vertically and horizontally stretched with optional top, left, bottom and right padding.
- Parameter child: A child UIView to layout.
- Parameter top: A CGFloat value for padding the top side.
- Parameter left: A CGFloat value for padding the left side.
- Parameter bottom: A CGFloat value for padding the bottom side.
- Parameter right: A CGFloat value for padding the right side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func edges(top: CGFloat = 0, left: CGFloat = 0, bottom: CGFloat = 0, right: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return edges(v, top: top, left: left, bottom: bottom, right: right, multiplier: multiplier)
}
/**
public func edges(top: CGFloat = 0, left: CGFloat = 0, bottom: CGFloat = 0, right: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return edges(v, top: top, left: left, bottom: bottom, right: right)
}
/**
A child view is aligned from the top with optional top padding.
- Parameter child: A child UIView to layout.
- Parameter top: A CGFloat value for padding the top side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func top(_ child: UIView, top: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.top(parent: v, child: child, top: top, multiplier: multiplier)
return self
}
/**
- Returns: The current Layout instance.
*/
public func top(_ child: UIView, top: CGFloat = 0) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.top(parent: v, child: child, top: top)
return self
}
/**
A child view is aligned from the top with optional top padding.
- Parameter top: A CGFloat value for padding the top side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func top(_ top: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return self.top(v, top: top, multiplier: multiplier)
}
/**
public func top(_ top: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return self.top(v, top: top)
}
/**
A child view is aligned from the left with optional left padding.
- Parameter child: A child UIView to layout.
- Parameter left: A CGFloat value for padding the left side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func left(_ child: UIView, left: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.left(parent: v, child: child, left: left, multiplier: multiplier)
return self
}
/**
- Returns: The current Layout instance.
*/
public func left(_ child: UIView, left: CGFloat = 0) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.left(parent: v, child: child, left: left)
return self
}
/**
A child view is aligned from the left with optional left padding.
- Parameter left: A CGFloat value for padding the left side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func left(_ left: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return self.left(v, left: left, multiplier: multiplier)
}
/**
public func left(_ left: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return self.left(v, left: left)
}
/**
A child view is aligned from the bottom with optional bottom padding.
- Parameter child: A child UIView to layout.
- Parameter bottom: A CGFloat value for padding the bottom side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func bottom(_ child: UIView, bottom: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.bottom(parent: v, child: child, bottom: bottom, multiplier: multiplier)
return self
}
/**
- Returns: The current Layout instance.
*/
public func bottom(_ child: UIView, bottom: CGFloat = 0) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.bottom(parent: v, child: child, bottom: bottom)
return self
}
/**
A child view is aligned from the bottom with optional bottom padding.
- Parameter bottom: A CGFloat value for padding the bottom side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func bottom(_ bottom: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return self.bottom(v, bottom: bottom, multiplier: multiplier)
}
/**
public func bottom(_ bottom: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return self.bottom(v, bottom: bottom)
}
/**
A child view is aligned from the right with optional right padding.
- Parameter child: A child UIView to layout.
- Parameter right: A CGFloat value for padding the right side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func right(_ child: UIView, right: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.right(parent: v, child: child, right: right, multiplier: multiplier)
return self
}
/**
- Returns: The current Layout instance.
*/
public func right(_ child: UIView, right: CGFloat = 0) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.right(parent: v, child: child, right: right)
return self
}
/**
A child view is aligned from the right with optional right padding.
- Parameter right: A CGFloat value for padding the right side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func right(_ right: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return self.right(v, right: right, multiplier: multiplier)
}
/**
public func right(_ right: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return self.right(v, right: right)
}
/**
A child view is aligned from the top left with optional top and left padding.
- Parameter child: A child UIView to layout.
- Parameter top: A CGFloat value for padding the top side.
- Parameter left: A CGFloat value for padding the left side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func topLeft(_ child: UIView, top: CGFloat = 0, left: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.topLeft(parent: v, child: child, top: top, left: left, multiplier: multiplier)
return self
}
/**
- Returns: The current Layout instance.
*/
public func topLeft(_ child: UIView, top: CGFloat = 0, left: CGFloat = 0) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.topLeft(parent: v, child: child, top: top, left: left)
return self
}
/**
A child view is aligned from the top left with optional top and left padding.
- Parameter top: A CGFloat value for padding the top side.
- Parameter left: A CGFloat value for padding the left side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func topLeft(top: CGFloat = 0, left: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return topLeft(v, top: top, left: left, multiplier: multiplier)
}
/**
public func topLeft(top: CGFloat = 0, left: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return topLeft(v, top: top, left: left)
}
/**
A child view is aligned from the top right with optional top and right padding.
- Parameter child: A child UIView to layout.
- Parameter top: A CGFloat value for padding the top side.
- Parameter right: A CGFloat value for padding the right side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func topRight(_ child: UIView, top: CGFloat = 0, right: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.topRight(parent: v, child: child, top: top, right: right, multiplier: multiplier)
return self
}
/**
- Returns: The current Layout instance.
*/
public func topRight(_ child: UIView, top: CGFloat = 0, right: CGFloat = 0) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.topRight(parent: v, child: child, top: top, right: right)
return self
}
/**
A child view is aligned from the top right with optional top and right padding.
- Parameter top: A CGFloat value for padding the top side.
- Parameter right: A CGFloat value for padding the right side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func topRight(top: CGFloat = 0, right: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return topRight(v, top: top, right: right, multiplier: multiplier)
}
/**
public func topRight(top: CGFloat = 0, right: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return topRight(v, top: top, right: right)
}
/**
A child view is aligned from the bottom left with optional bottom and left padding.
- Parameter child: A child UIView to layout.
- Parameter bottom: A CGFloat value for padding the bottom side.
- Parameter left: A CGFloat value for padding the left side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func bottomLeft(_ child: UIView, bottom: CGFloat = 0, left: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.bottomLeft(parent: v, child: child, bottom: bottom, left: left, multiplier: multiplier)
return self
}
/**
- Returns: The current Layout instance.
*/
public func bottomLeft(_ child: UIView, bottom: CGFloat = 0, left: CGFloat = 0) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.bottomLeft(parent: v, child: child, bottom: bottom, left: left)
return self
}
/**
A child view is aligned from the bottom left with optional bottom and left padding.
- Parameter bottom: A CGFloat value for padding the bottom side.
- Parameter left: A CGFloat value for padding the left side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func bottomLeft(bottom: CGFloat = 0, left: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return bottomLeft(v, bottom: bottom, left: left, multiplier: multiplier)
}
/**
public func bottomLeft(bottom: CGFloat = 0, left: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return bottomLeft(v, bottom: bottom, left: left)
}
/**
A child view is aligned from the bottom right with optional bottom and right padding.
- Parameter child: A child UIView to layout.
- Parameter bottom: A CGFloat value for padding the bottom side.
- Parameter right: A CGFloat value for padding the right side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func bottomRight(_ child: UIView, bottom: CGFloat = 0, right: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.bottomRight(parent: v, child: child, bottom: bottom, right: right, multiplier: multiplier)
return self
}
/**
- Returns: The current Layout instance.
*/
public func bottomRight(_ child: UIView, bottom: CGFloat = 0, right: CGFloat = 0) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.bottomRight(parent: v, child: child, bottom: bottom, right: right)
return self
}
/**
A child view is aligned from the bottom right with optional bottom and right padding.
- Parameter bottom: A CGFloat value for padding the bottom side.
- Parameter right: A CGFloat value for padding the right side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func bottomRight(bottom: CGFloat = 0, right: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return bottomRight(v, bottom: bottom, right: right, multiplier: multiplier)
}
/**
public func bottomRight(bottom: CGFloat = 0, right: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return bottomRight(v, bottom: bottom, right: right)
}
/**
A child view is aligned at the center with an optional offsetX and offsetY value.
- Parameter child: A child UIView to layout.
- Parameter offsetX: A CGFloat value for the offset along the x axis.
- Parameter offsetX: A CGFloat value for the offset along the y axis.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func center(_ child: UIView, offsetX: CGFloat = 0, offsetY: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
public func center(_ child: UIView, offsetX: CGFloat = 0, offsetY: CGFloat = 0) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.center(parent: v, child: child, offsetX: offsetX, offsetY: offsetY, multiplier: multiplier)
self.child = child
Layout.center(parent: v, child: child, offsetX: offsetX, offsetY: offsetY)
return self
}
/**
}
/**
A child view is aligned at the center with an optional offsetX and offsetY value.
- Parameter offsetX: A CGFloat value for the offset along the x axis.
- Parameter offsetX: A CGFloat value for the offset along the y axis.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func center(offsetX: CGFloat = 0, offsetY: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
public func center(offsetX: CGFloat = 0, offsetY: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return center(v, offsetX: offsetX, offsetY: offsetY, multiplier: multiplier)
return center(v, offsetX: offsetX, offsetY: offsetY)
}
/**
/**
A child view is aligned at the center horizontally with an optional offset value.
- Parameter child: A child UIView to layout.
- Parameter offset: A CGFloat value for the offset along the x axis.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func centerHorizontally(_ child: UIView, offset: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
public func centerHorizontally(_ child: UIView, offset: CGFloat = 0) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.centerHorizontally(parent: v, child: child, offset: offset, multiplier: multiplier)
self.child = child
Layout.centerHorizontally(parent: v, child: child, offset: offset)
return self
}
}
/**
/**
A child view is aligned at the center horizontally with an optional offset value.
- Parameter offset: A CGFloat value for the offset along the x axis.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func centerHorizontally(offset: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
public func centerHorizontally(offset: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return centerHorizontally(v, offset: offset, multiplier: multiplier)
return centerHorizontally(v, offset: offset)
}
/**
/**
A child view is aligned at the center vertically with an optional offset value.
- Parameter child: A child UIView to layout.
- Parameter offset: A CGFloat value for the offset along the y axis.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func centerVertically(_ child: UIView, offset: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
public func centerVertically(_ child: UIView, offset: CGFloat = 0) -> Layout {
guard let v = parent else {
return debugParentNotAvailableMessage()
}
self.child = child
Layout.centerVertically(parent: v, child: child, offset: offset, multiplier: multiplier)
self.child = child
Layout.centerVertically(parent: v, child: child, offset: offset)
return self
}
}
/**
/**
A child view is aligned at the center vertically with an optional offset value.
- Parameter offset: A CGFloat value for the offset along the y axis.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public func centerVertically(offset: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
public func centerVertically(offset: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return centerVertically(v, offset: offset, multiplier: multiplier)
return centerVertically(v, offset: offset)
}
}
/// Layout
extension Layout {
/**
/**
Sets the width of a view.
- Parameter parent: A parent UIView context.
- Parameter child: A child UIView to layout.
- Parameter multiplier: A CGFloat value.
- Parameter width: A CGFloat value.
*/
public class func width(parent: UIView, child: UIView, width: CGFloat = 0, multiplier: CGFloat = 1) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: multiplier, constant: width))
}
/**
public class func width(parent: UIView, child: UIView, width: CGFloat = 0) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1, constant: width))
}
/**
Sets the height of a view.
- Parameter parent: A parent UIView context.
- Parameter child: A child UIView to layout.
- Parameter multiplier: A CGFloat value.
- Parameter height: A CGFloat value.
*/
public class func height(parent: UIView, child: UIView, height: CGFloat = 0, multiplier: CGFloat = 1) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: multiplier, constant: height))
}
/**
public class func height(parent: UIView, child: UIView, height: CGFloat = 0) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1, constant: height))
}
/**
Sets the width and height of a view.
- Parameter parent: A parent UIView context.
- Parameter child: A child UIView to layout.
- Parameter multiplier: A CGFloat value.
- Parameter size: A CGSize value.
*/
public class func size(parent: UIView, child: UIView, size: CGSize = CGSize.zero, multiplier: CGFloat = 1) {
Layout.width(parent: parent, child: child, width: size.width, multiplier: multiplier)
Layout.height(parent: parent, child: child, height: size.height, multiplier: multiplier)
}
/**
public class func size(parent: UIView, child: UIView, size: CGSize = CGSize.zero) {
Layout.width(parent: parent, child: child, width: size.width)
Layout.height(parent: parent, child: child, height: size.height)
}
/**
A collection of children views are horizontally stretched with optional left,
right padding and interim interimSpace.
- Parameter parent: A parent UIView context.
......@@ -674,23 +635,20 @@ extension Layout {
- Parameter left: A CGFloat value for padding the left side.
- Parameter right: A CGFloat value for padding the right side.
- Parameter interimSpace: A CGFloat value for interim interimSpace.
- Parameter multiplier: A CGFloat value.
*/
public class func horizontally(parent: UIView, children: [UIView], left: CGFloat = 0, right: CGFloat = 0, interimSpace: InterimSpace = 0, multiplier: CGFloat = 1) {
guard 0 < children.count else {
return
}
public class func horizontally(parent: UIView, children: [UIView], left: CGFloat = 0, right: CGFloat = 0, interimSpace: InterimSpace = 0) {
prepareForConstraint(parent, children: children)
parent.addConstraint(NSLayoutConstraint(item: children[0], attribute: .left, relatedBy: .equal, toItem: parent, attribute: .left, multiplier: multiplier, constant: left))
for i in 1..<children.count {
parent.addConstraint(NSLayoutConstraint(item: children[i], attribute: .left, relatedBy: .equal, toItem: children[i - 1], attribute: .right, multiplier: multiplier, constant: interimSpace))
parent.addConstraint(NSLayoutConstraint(item: children[i], attribute: .width, relatedBy: .equal, toItem: children[0], attribute: .width, multiplier: multiplier, constant: 0))
}
parent.addConstraint(NSLayoutConstraint(item: children[children.count - 1], attribute: .right, relatedBy: .equal, toItem: parent, attribute: .right, multiplier: multiplier, constant: -right))
}
/**
if 0 < children.count {
parent.addConstraint(NSLayoutConstraint(item: children[0], attribute: .left, relatedBy: .equal, toItem: parent, attribute: .left, multiplier: 1, constant: left))
for i in 1..<children.count {
parent.addConstraint(NSLayoutConstraint(item: children[i], attribute: .left, relatedBy: .equal, toItem: children[i - 1], attribute: .right, multiplier: 1, constant: interimSpace))
parent.addConstraint(NSLayoutConstraint(item: children[i], attribute: .width, relatedBy: .equal, toItem: children[0], attribute: .width, multiplier: 1, constant: 0))
}
parent.addConstraint(NSLayoutConstraint(item: children[children.count - 1], attribute: .right, relatedBy: .equal, toItem: parent, attribute: .right, multiplier: 1, constant: -right))
}
}
/**
A collection of children views are vertically stretched with optional top,
bottom padding and interim interimSpace.
- Parameter parent: A parent UIView context.
......@@ -698,51 +656,46 @@ extension Layout {
- Parameter top: A CGFloat value for padding the top side.
- Parameter bottom: A CGFloat value for padding the bottom side.
- Parameter interimSpace: A CGFloat value for interim interimSpace.
- Parameter multiplier: A CGFloat value.
*/
public class func vertically(parent: UIView, children: [UIView], top: CGFloat = 0, bottom: CGFloat = 0, interimSpace: InterimSpace = 0, multiplier: CGFloat = 1) {
guard 0 < children.count else {
return
}
public class func vertically(parent: UIView, children: [UIView], top: CGFloat = 0, bottom: CGFloat = 0, interimSpace: InterimSpace = 0) {
prepareForConstraint(parent, children: children)
parent.addConstraint(NSLayoutConstraint(item: children[0], attribute: .top, relatedBy: .equal, toItem: parent, attribute: .top, multiplier: multiplier, constant: top))
for i in 1..<children.count {
parent.addConstraint(NSLayoutConstraint(item: children[i], attribute: .top, relatedBy: .equal, toItem: children[i - 1], attribute: .bottom, multiplier: multiplier, constant: interimSpace))
parent.addConstraint(NSLayoutConstraint(item: children[i], attribute: .height, relatedBy: .equal, toItem: children[0], attribute: .height, multiplier: multiplier, constant: 0))
}
parent.addConstraint(NSLayoutConstraint(item: children[children.count - 1], attribute: .bottom, relatedBy: .equal, toItem: parent, attribute: .bottom, multiplier: multiplier, constant: -bottom))
}
/**
if 0 < children.count {
parent.addConstraint(NSLayoutConstraint(item: children[0], attribute: .top, relatedBy: .equal, toItem: parent, attribute: .top, multiplier: 1, constant: top))
for i in 1..<children.count {
parent.addConstraint(NSLayoutConstraint(item: children[i], attribute: .top, relatedBy: .equal, toItem: children[i - 1], attribute: .bottom, multiplier: 1, constant: interimSpace))
parent.addConstraint(NSLayoutConstraint(item: children[i], attribute: .height, relatedBy: .equal, toItem: children[0], attribute: .height, multiplier: 1, constant: 0))
}
parent.addConstraint(NSLayoutConstraint(item: children[children.count - 1], attribute: .bottom, relatedBy: .equal, toItem: parent, attribute: .bottom, multiplier: 1, constant: -bottom))
}
}
/**
A child view is horizontally stretched with optional left and right padding.
- Parameter parent: A parent UIView context.
- Parameter child: A child UIView to layout.
- Parameter left: A CGFloat value for padding the left side.
- Parameter right: A CGFloat value for padding the right side.
- Parameter multiplier: A CGFloat value.
*/
public class func horizontally(parent: UIView, child: UIView, left: CGFloat = 0, right: CGFloat = 0, multiplier: CGFloat = 1) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .left, relatedBy: .equal, toItem: parent, attribute: .left, multiplier: multiplier, constant: left))
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .right, relatedBy: .equal, toItem: parent, attribute: .right, multiplier: multiplier, constant: -right))
}
/**
*/
public class func horizontally(parent: UIView, child: UIView, left: CGFloat = 0, right: CGFloat = 0) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .left, relatedBy: .equal, toItem: parent, attribute: .left, multiplier: 1, constant: left))
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .right, relatedBy: .equal, toItem: parent, attribute: .right, multiplier: 1, constant: -right))
}
/**
A child view is vertically stretched with optional left and right padding.
- Parameter parent: A parent UIView context.
- Parameter child: A child UIView to layout.
- Parameter top: A CGFloat value for padding the top side.
- Parameter bottom: A CGFloat value for padding the bottom side.
- Parameter multiplier: A CGFloat value.
*/
public class func vertically(parent: UIView, child: UIView, top: CGFloat = 0, bottom: CGFloat = 0, multiplier: CGFloat = 1) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .top, relatedBy: .equal, toItem: parent, attribute: .top, multiplier: multiplier, constant: top))
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .bottom, relatedBy: .equal, toItem: parent, attribute: .bottom, multiplier: multiplier, constant: -bottom))
}
/**
*/
public class func vertically(parent: UIView, child: UIView, top: CGFloat = 0, bottom: CGFloat = 0) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .top, relatedBy: .equal, toItem: parent, attribute: .top, multiplier: 1, constant: top))
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .bottom, relatedBy: .equal, toItem: parent, attribute: .bottom, multiplier: 1, constant: -bottom))
}
/**
A child view is vertically and horizontally stretched with optional top, left, bottom and right padding.
- Parameter parent: A parent UIView context.
- Parameter child: A child UIView to layout.
......@@ -750,162 +703,150 @@ extension Layout {
- Parameter left: A CGFloat value for padding the left side.
- Parameter bottom: A CGFloat value for padding the bottom side.
- Parameter right: A CGFloat value for padding the right side.
- Parameter multiplier: A CGFloat value.
*/
public class func edges(parent: UIView, child: UIView, top: CGFloat = 0, left: CGFloat = 0, bottom: CGFloat = 0, right: CGFloat = 0, multiplier: CGFloat = 1) {
horizontally(parent: parent, child: child, left: left, right: right, multiplier: multiplier)
vertically(parent: parent, child: child, top: top, bottom: bottom, multiplier: multiplier)
}
/**
*/
public class func edges(parent: UIView, child: UIView, top: CGFloat = 0, left: CGFloat = 0, bottom: CGFloat = 0, right: CGFloat = 0) {
horizontally(parent: parent, child: child, left: left, right: right)
vertically(parent: parent, child: child, top: top, bottom: bottom)
}
/**
A child view is aligned from the top with optional top padding.
- Parameter parent: A parent UIView context.
- Parameter child: A child UIView to layout.
- Parameter top: A CGFloat value for padding the top side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public class func top(parent: UIView, child: UIView, top: CGFloat = 0, multiplier: CGFloat = 1) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .top, relatedBy: .equal, toItem: parent, attribute: .top, multiplier: multiplier, constant: top))
}
/**
public class func top(parent: UIView, child: UIView, top: CGFloat = 0) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .top, relatedBy: .equal, toItem: parent, attribute: .top, multiplier: 1, constant: top))
}
/**
A child view is aligned from the left with optional left padding.
- Parameter parent: A parent UIView context.
- Parameter child: A child UIView to layout.
- Parameter left: A CGFloat value for padding the left side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public class func left(parent: UIView, child: UIView, left: CGFloat = 0, multiplier: CGFloat = 1) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .left, relatedBy: .equal, toItem: parent, attribute: .left, multiplier: multiplier, constant: left))
}
/**
public class func left(parent: UIView, child: UIView, left: CGFloat = 0) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .left, relatedBy: .equal, toItem: parent, attribute: .left, multiplier: 1, constant: left))
}
/**
A child view is aligned from the bottom with optional bottom padding.
- Parameter parent: A parent UIView context.
- Parameter child: A child UIView to layout.
- Parameter bottom: A CGFloat value for padding the bottom side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public class func bottom(parent: UIView, child: UIView, bottom: CGFloat = 0, multiplier: CGFloat = 1) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .bottom, relatedBy: .equal, toItem: parent, attribute: .bottom, multiplier: multiplier, constant: -bottom))
}
/**
public class func bottom(parent: UIView, child: UIView, bottom: CGFloat = 0) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .bottom, relatedBy: .equal, toItem: parent, attribute: .bottom, multiplier: 1, constant: -bottom))
}
/**
A child view is aligned from the right with optional right padding.
- Parameter parent: A parent UIView context.
- Parameter child: A child UIView to layout.
- Parameter right: A CGFloat value for padding the right side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public class func right(parent: UIView, child: UIView, right: CGFloat = 0, multiplier: CGFloat = 1) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .right, relatedBy: .equal, toItem: parent, attribute: .right, multiplier: multiplier, constant: -right))
}
/**
public class func right(parent: UIView, child: UIView, right: CGFloat = 0) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .right, relatedBy: .equal, toItem: parent, attribute: .right, multiplier: 1, constant: -right))
}
/**
A child view is aligned from the top left with optional top and left padding.
- Parameter parent: A parent UIView context.
- Parameter child: A child UIView to layout.
- Parameter top: A CGFloat value for padding the top side.
- Parameter left: A CGFloat value for padding the left side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public class func topLeft(parent: UIView, child: UIView, top t: CGFloat = 0, left l: CGFloat = 0, multiplier: CGFloat = 1) {
top(parent: parent, child: child, top: t, multiplier: multiplier)
left(parent: parent, child: child, left: l, multiplier: multiplier)
}
/**
public class func topLeft(parent: UIView, child: UIView, top t: CGFloat = 0, left l: CGFloat = 0) {
top(parent: parent, child: child, top: t)
left(parent: parent, child: child, left: l)
}
/**
A child view is aligned from the top right with optional top and right padding.
- Parameter parent: A parent UIView context.
- Parameter child: A child UIView to layout.
- Parameter top: A CGFloat value for padding the top side.
- Parameter right: A CGFloat value for padding the right side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public class func topRight(parent: UIView, child: UIView, top t: CGFloat = 0, right r: CGFloat = 0, multiplier: CGFloat = 1) {
top(parent: parent, child: child, top: t, multiplier: multiplier)
right(parent: parent, child: child, right: r, multiplier: multiplier)
}
/**
public class func topRight(parent: UIView, child: UIView, top t: CGFloat = 0, right r: CGFloat = 0) {
top(parent: parent, child: child, top: t)
right(parent: parent, child: child, right: r)
}
/**
A child view is aligned from the bottom left with optional bottom and left padding.
- Parameter parent: A parent UIView context.
- Parameter child: A child UIView to layout.
- Parameter bottom: A CGFloat value for padding the bottom side.
- Parameter left: A CGFloat value for padding the left side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public class func bottomLeft(parent: UIView, child: UIView, bottom b: CGFloat = 0, left l: CGFloat = 0, multiplier: CGFloat = 1) {
bottom(parent: parent, child: child, bottom: b, multiplier: multiplier)
left(parent: parent, child: child, left: l, multiplier: multiplier)
}
/**
public class func bottomLeft(parent: UIView, child: UIView, bottom b: CGFloat = 0, left l: CGFloat = 0) {
bottom(parent: parent, child: child, bottom: b)
left(parent: parent, child: child, left: l)
}
/**
A child view is aligned from the bottom right with optional bottom and right padding.
- Parameter parent: A parent UIView context.
- Parameter child: A child UIView to layout.
- Parameter bottom: A CGFloat value for padding the bottom side.
- Parameter right: A CGFloat value for padding the right side.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public class func bottomRight(parent: UIView, child: UIView, bottom b: CGFloat = 0, right r: CGFloat = 0, multiplier: CGFloat = 1) {
bottom(parent: parent, child: child, bottom: b, multiplier: multiplier)
right(parent: parent, child: child, right: r, multiplier: multiplier)
}
/**
public class func bottomRight(parent: UIView, child: UIView, bottom b: CGFloat = 0, right r: CGFloat = 0) {
bottom(parent: parent, child: child, bottom: b)
right(parent: parent, child: child, right: r)
}
/**
A child view is aligned at the center with an optional offsetX and offsetY value.
- Parameter parent: A parent UIView context.
- Parameter child: A child UIView to layout.
- Parameter offsetX: A CGFloat value for the offset along the x axis.
- Parameter offsetX: A CGFloat value for the offset along the y axis.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public class func center(parent: UIView, child: UIView, offsetX: CGFloat = 0, offsetY: CGFloat = 0, multiplier: CGFloat = 1) {
centerHorizontally(parent: parent, child: child, offset: offsetX, multiplier: multiplier)
centerVertically(parent: parent, child: child, offset: offsetY, multiplier: multiplier)
}
/**
public class func center(parent: UIView, child: UIView, offsetX: CGFloat = 0, offsetY: CGFloat = 0) {
centerHorizontally(parent: parent, child: child, offset: offsetX)
centerVertically(parent: parent, child: child, offset: offsetY)
}
/**
A child view is aligned at the center horizontally with an optional offset value.
- Parameter parent: A parent UIView context.
- Parameter child: A child UIView to layout.
- Parameter offset: A CGFloat value for the offset along the y axis.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public class func centerHorizontally(parent: UIView, child: UIView, offset: CGFloat = 0, multiplier: CGFloat = 1) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .centerX, relatedBy: .equal, toItem: parent, attribute: .centerX, multiplier: multiplier, constant: offset))
}
/**
public class func centerHorizontally(parent: UIView, child: UIView, offset: CGFloat = 0) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .centerX, relatedBy: .equal, toItem: parent, attribute: .centerX, multiplier: 1, constant: offset))
}
/**
A child view is aligned at the center vertically with an optional offset value.
- Parameter parent: A parent UIView context.
- Parameter child: A child UIView to layout.
- Parameter offset: A CGFloat value for the offset along the y axis.
- Parameter multiplier: A CGFloat value.
- Returns: The current Layout instance.
*/
public class func centerVertically(parent: UIView, child: UIView, offset: CGFloat = 0, multiplier: CGFloat = 1) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .centerY, relatedBy: .equal, toItem: parent, attribute: .centerY, multiplier: multiplier, constant: offset))
}
/**
public class func centerVertically(parent: UIView, child: UIView, offset: CGFloat = 0) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .centerY, relatedBy: .equal, toItem: parent, attribute: .centerY, multiplier: 1, constant: offset))
}
/**
Creats an Array with a NSLayoutConstraint value.
- Parameter format: The VFL format string.
- Parameter options: Additional NSLayoutFormatOptions.
......@@ -914,45 +855,45 @@ extension Layout {
- Returns: The Array<NSLayoutConstraint> instance.
*/
public class func constraint(format: String, options: NSLayoutFormatOptions, metrics: [String: Any]?, views: [String: Any]) -> [NSLayoutConstraint] {
for (_, a) in views {
if let v = a as? UIView {
v.translatesAutoresizingMaskIntoConstraints = false
}
}
return NSLayoutConstraint.constraints(
withVisualFormat: format,
options: options,
metrics: metrics,
views: views
)
}
/**
for (_, a) in views {
if let v = a as? UIView {
v.translatesAutoresizingMaskIntoConstraints = false
}
}
return NSLayoutConstraint.constraints(
withVisualFormat: format,
options: options,
metrics: metrics,
views: views
)
}
/**
Prepares the relationship between the parent view context and child view
to layout. If the child is not already added to the view hierarchy as the
parent's child, then it is added.
- Parameter parent: A parent UIView context.
- Parameter child: A child UIView to layout.
*/
private class func prepareForConstraint(_ parent: UIView, child: UIView) {
if parent != child.superview {
child.removeFromSuperview()
parent.addSubview(child)
}
child.translatesAutoresizingMaskIntoConstraints = false
}
/**
private class func prepareForConstraint(_ parent: UIView, child: UIView) {
if parent != child.superview {
child.removeFromSuperview()
parent.addSubview(child)
}
child.translatesAutoresizingMaskIntoConstraints = false
}
/**
Prepares the relationship between the parent view context and an Array of
child UIViews.
- Parameter parent: A parent UIView context.
- Parameter children: An Array of UIViews.
*/
private class func prepareForConstraint(_ parent: UIView, children: [UIView]) {
for v in children {
prepareForConstraint(parent, child: v)
}
}
private class func prepareForConstraint(_ parent: UIView, children: [UIView]) {
for v in children {
prepareForConstraint(parent, child: v)
}
}
}
/// A memory reference to the LayoutKey instance for UIView extensions.
......@@ -960,19 +901,19 @@ private var LayoutKey: UInt8 = 0
/// Layout extension for UIView.
extension UIView {
/// Layout reference.
public private(set) var layout: Layout {
get {
return AssociatedObject(base: self, key: &LayoutKey) {
return Layout(parent: self)
}
}
set(value) {
AssociateObject(base: self, key: &LayoutKey, value: value)
}
}
/**
/// Layout reference.
public private(set) var layout: Layout {
get {
return AssociatedObject(base: self, key: &LayoutKey) {
return Layout(parent: self)
}
}
set(value) {
AssociateObject(base: self, key: &LayoutKey, value: value)
}
}
/**
Used to chain layout constraints on a child context.
- Parameter child: A child UIView to layout.
- Returns: The current Layout instance.
......
......@@ -30,38 +30,38 @@
import UIKit
@objc(SwitchControlStyle)
public enum SwitchControlStyle: Int {
@objc(SwitchStyle)
public enum SwitchStyle: Int {
case light
case dark
}
@objc(SwitchControlState)
public enum SwitchControlState: Int {
@objc(SwitchState)
public enum SwitchState: Int {
case on
case off
}
@objc(SwitchControlSize)
public enum SwitchControlSize: Int {
@objc(SwitchSize)
public enum SwitchSize: Int {
case small
case medium
case large
}
@objc(SwitchControlDelegate)
public protocol SwitchControlDelegate {
@objc(SwitchDelegate)
public protocol SwitchDelegate {
/**
A SwitchControl delegate method for state changes.
- Parameter control: SwitchControl control.
A Switch delegate method for state changes.
- Parameter control: Switch control.
*/
func switchStateChanged(control: SwitchControl)
func switchStateChanged(control: Switch)
}
@objc(SwitchControl)
open class SwitchControl: UIControl {
@objc(Switch)
open class Switch: UIControl {
/// An internal reference to the switchState public property.
private var internalSwitchControlState: SwitchControlState = .off
private var internalSwitchState: SwitchState = .off
/// Track thickness.
private var trackThickness: CGFloat = 0
......@@ -79,7 +79,7 @@ open class SwitchControl: UIControl {
private var bounceOffset: CGFloat = 3
/// An Optional delegation method.
open weak var delegate: SwitchControlDelegate?
open weak var delegate: SwitchDelegate?
/// Indicates if the animation should bounce.
@IBInspectable
......@@ -170,7 +170,7 @@ open class SwitchControl: UIControl {
@IBInspectable
open override var isEnabled: Bool {
didSet {
styleForState(state: internalSwitchControlState)
styleForState(state: internalSwitchState)
}
}
......@@ -178,27 +178,27 @@ open class SwitchControl: UIControl {
@IBInspectable
public var on: Bool {
get {
return .on == internalSwitchControlState
return .on == internalSwitchState
}
set(value) {
setOn(on: value, animated: true)
}
}
/// SwitchControl state.
public var switchState: SwitchControlState {
/// Switch state.
public var switchState: SwitchState {
get {
return internalSwitchControlState
return internalSwitchState
}
set(value) {
if value != internalSwitchControlState {
internalSwitchControlState = value
if value != internalSwitchState {
internalSwitchState = value
}
}
}
/// SwitchControl style.
public var switchStyle: SwitchControlStyle = .dark {
/// Switch style.
public var switchStyle: SwitchStyle = .dark {
didSet {
switch switchStyle {
case .light:
......@@ -223,8 +223,8 @@ open class SwitchControl: UIControl {
}
}
/// SwitchControl size.
public var switchSize: SwitchControlSize = .medium {
/// Switch size.
public var switchSize: SwitchSize = .medium {
didSet {
switch switchSize {
case .small:
......@@ -245,13 +245,13 @@ open class SwitchControl: UIControl {
open override var frame: CGRect {
didSet {
layoutSwitchControl()
layoutSwitch()
}
}
open override var bounds: CGRect {
didSet {
layoutSwitchControl()
layoutSwitch()
}
}
......@@ -276,9 +276,9 @@ open class SwitchControl: UIControl {
super.init(coder: aDecoder)
prepareTrack()
prepareButton()
prepareSwitchControlSize(size: .medium)
prepareSwitchControlStyle(style: .light)
prepareSwitchControlState(state: .off)
prepareSwitchSize(size: .medium)
prepareSwitchStyle(style: .light)
prepareSwitchState(state: .off)
}
/**
......@@ -294,39 +294,39 @@ open class SwitchControl: UIControl {
super.init(frame: frame)
prepareTrack()
prepareButton()
prepareSwitchControlSize(size: .medium)
prepareSwitchControlStyle(style: .light)
prepareSwitchControlState(state: .off)
prepareSwitchSize(size: .medium)
prepareSwitchStyle(style: .light)
prepareSwitchState(state: .off)
}
/**
An initializer that sets the state, style, and size of the SwitchControl instance.
- Parameter state: A SwitchControlState value.
- Parameter style: A SwitchControlStyle value.
- Parameter size: A SwitchControlSize value.
An initializer that sets the state, style, and size of the Switch instance.
- Parameter state: A SwitchState value.
- Parameter style: A SwitchStyle value.
- Parameter size: A SwitchSize value.
*/
public init(state: SwitchControlState = .off, style: SwitchControlStyle = .dark, size: SwitchControlSize = .medium) {
public init(state: SwitchState = .off, style: SwitchStyle = .dark, size: SwitchSize = .medium) {
trackLayer = CAShapeLayer()
button = FabButton()
super.init(frame: CGRect.null)
prepareTrack()
prepareButton()
prepareSwitchControlSize(size: size)
prepareSwitchControlStyle(style: style)
prepareSwitchControlState(state: state)
prepareSwitchSize(size: size)
prepareSwitchStyle(style: style)
prepareSwitchState(state: state)
}
open override func willMove(toSuperview newSuperview: UIView?) {
super.willMove(toSuperview: newSuperview)
styleForState(state: internalSwitchControlState)
styleForState(state: internalSwitchState)
}
/**
Toggle the SwitchControl state, if On will be Off, and if Off will be On.
Toggle the Switch state, if On will be Off, and if Off will be On.
- Parameter completion: An Optional completion block.
*/
public func toggle(completion: ((SwitchControl) -> Void)? = nil) {
setSwitchControlState(state: .on == internalSwitchControlState ? .off : .on, animated: true, completion: completion)
public func toggle(completion: ((Switch) -> Void)? = nil) {
setSwitchState(state: .on == internalSwitchState ? .off : .on, animated: true, completion: completion)
}
/**
......@@ -334,22 +334,22 @@ open class SwitchControl: UIControl {
- Parameter on: A bool of whether the switch should be in the on state or not.
- Parameter animated: A Boolean indicating to set the animation or not.
*/
public func setOn(on: Bool, animated: Bool, completion: ((SwitchControl) -> Void)? = nil) {
setSwitchControlState(state: on ? .on : .off, animated: animated, completion: completion)
public func setOn(on: Bool, animated: Bool, completion: ((Switch) -> Void)? = nil) {
setSwitchState(state: on ? .on : .off, animated: animated, completion: completion)
}
/**
Set the switchState property with an option to animate.
- Parameter state: The SwitchControlState to set.
- Parameter state: The SwitchState to set.
- Parameter animated: A Boolean indicating to set the animation or not.
- Parameter completion: An Optional completion block.
*/
public func setSwitchControlState(state: SwitchControlState, animated: Bool = true, completion: ((SwitchControl) -> Void)? = nil) {
if isEnabled && internalSwitchControlState != state {
internalSwitchControlState = state
public func setSwitchState(state: SwitchState, animated: Bool = true, completion: ((Switch) -> Void)? = nil) {
if isEnabled && internalSwitchState != state {
internalSwitchState = state
if animated {
animateToState(state: state) { [weak self] _ in
if let s: SwitchControl = self {
if let s: Switch = self {
s.sendActions(for: .valueChanged)
completion?(s)
s.delegate?.switchStateChanged(control: s)
......@@ -374,7 +374,7 @@ open class SwitchControl: UIControl {
internal func handleTouchUpOutsideOrCanceled(sender: FabButton, event: UIEvent) {
if let v: UITouch = event.touches(for: sender)?.first {
let q: CGFloat = sender.x + v.location(in: sender).x - v.previousLocation(in: sender).x
setSwitchControlState(state: q > (width - button.width) / 2 ? .on : .off, animated: true)
setSwitchState(state: q > (width - button.width) / 2 ? .on : .off, animated: true)
}
}
......@@ -401,7 +401,7 @@ open class SwitchControl: UIControl {
open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if true == trackLayer.frame.contains(layer.convert(touches.first!.location(in: self), from: layer)) {
setOn(on: .on != internalSwitchControlState, animated: true)
setOn(on: .on != internalSwitchState, animated: true)
}
}
......@@ -423,35 +423,35 @@ open class SwitchControl: UIControl {
/**
Prepares the switchState property. This is used mainly to allow
init to set the state value and have an effect.
- Parameter state: The SwitchControlState to set.
- Parameter state: The SwitchState to set.
*/
private func prepareSwitchControlState(state: SwitchControlState) {
setSwitchControlState(state: state, animated: false)
private func prepareSwitchState(state: SwitchState) {
setSwitchState(state: state, animated: false)
}
/**
Prepares the switchStyle property. This is used mainly to allow
init to set the state value and have an effect.
- Parameter style: The SwitchControlStyle to set.
- Parameter style: The SwitchStyle to set.
*/
private func prepareSwitchControlStyle(style: SwitchControlStyle) {
private func prepareSwitchStyle(style: SwitchStyle) {
switchStyle = style
}
/**
Prepares the switchSize property. This is used mainly to allow
init to set the size value and have an effect.
- Parameter size: The SwitchControlSize to set.
- Parameter size: The SwitchSize to set.
*/
private func prepareSwitchControlSize(size: SwitchControlSize) {
private func prepareSwitchSize(size: SwitchSize) {
switchSize = size
}
/**
Updates the style based on the state.
- Parameter state: The SwitchControlState to set the style to.
- Parameter state: The SwitchState to set the style to.
*/
private func styleForState(state: SwitchControlState) {
private func styleForState(state: SwitchState) {
if isEnabled {
updateColorForState(state: state)
} else {
......@@ -461,9 +461,9 @@ open class SwitchControl: UIControl {
/**
Updates the coloring for the enabled state.
- Parameter state: SwitchControlState.
- Parameter state: SwitchState.
*/
private func updateColorForState(state: SwitchControlState) {
private func updateColorForState(state: SwitchState) {
if .on == state {
button.backgroundColor = buttonOnColor
trackLayer.backgroundColor = trackOnColor.cgColor
......@@ -475,9 +475,9 @@ open class SwitchControl: UIControl {
/**
Updates the coloring for the disabled state.
- Parameter state: SwitchControlState.
- Parameter state: SwitchState.
*/
private func updateColorForDisabledState(state: SwitchControlState) {
private func updateColorForDisabledState(state: SwitchState) {
if .on == state {
button.backgroundColor = buttonOnDisabledColor
trackLayer.backgroundColor = trackOnDisabledColor.cgColor
......@@ -488,7 +488,7 @@ open class SwitchControl: UIControl {
}
/// Laout the button and track views.
private func layoutSwitchControl() {
private func layoutSwitch() {
var w: CGFloat = 0
switch switchSize {
case .small:
......@@ -508,34 +508,34 @@ open class SwitchControl: UIControl {
onPosition = width - px - buttonDiameter
offPosition = px
if .on == internalSwitchControlState {
if .on == internalSwitchState {
button.x = onPosition
}
}
/**
Set the switchState property with an animate.
- Parameter state: The SwitchControlState to set.
- Parameter state: The SwitchState to set.
- Parameter completion: An Optional completion block.
*/
private func animateToState(state: SwitchControlState, completion: ((SwitchControl) -> Void)? = nil) {
private func animateToState(state: SwitchState, completion: ((Switch) -> Void)? = nil) {
isUserInteractionEnabled = false
UIView.animate(withDuration: 0.15,
delay: 0.05,
options: [.curveEaseIn, .curveEaseOut],
animations: { [weak self] in
if let s: SwitchControl = self {
if let s: Switch = self {
s.button.x = .on == state ? s.onPosition + s.bounceOffset : s.offPosition - s.bounceOffset
s.styleForState(state: state)
}
}) { [weak self] _ in
UIView.animate(withDuration: 0.15,
animations: { [weak self] in
if let s: SwitchControl = self {
if let s: Switch = self {
s.button.x = .on == state ? s.onPosition : s.offPosition
}
}) { [weak self] _ in
if let s: SwitchControl = self {
if let s: Switch = self {
s.isUserInteractionEnabled = true
completion?(s)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment