Commit 09cdb27c by Daniel Dahan

development: updated SwitchControl to Switch

parent 412c2ca7
......@@ -81,87 +81,81 @@ public class Layout {
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 {
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)
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 {
public func width(_ width: CGFloat) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return self.width(v, width: width, multiplier: multiplier)
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 {
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)
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 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 {
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)
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 self.size(v, size: size, multiplier: multiplier)
return self.size(v, size: size)
}
/**
......@@ -171,14 +165,13 @@ public class 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 {
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
}
......@@ -189,14 +182,13 @@ public class 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 {
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
}
......@@ -205,15 +197,14 @@ public class Layout {
- 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 {
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)
Layout.horizontally(parent: v, child: child, left: left, right: right)
return self
}
......@@ -221,14 +212,13 @@ public class Layout {
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)
}
/**
......@@ -236,15 +226,14 @@ public class Layout {
- 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 {
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)
Layout.vertically(parent: v, child: child, top: top, bottom: bottom)
return self
}
......@@ -252,14 +241,13 @@ public class Layout {
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)
}
/**
......@@ -269,15 +257,14 @@ public class 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.
- 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 {
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, multiplier: multiplier)
Layout.edges(parent: v, child: child, top: top, left: left, bottom: bottom, right: right)
return self
}
......@@ -288,130 +275,121 @@ public class 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.
- Returns: The current Layout instance.
*/
public func edges(top: CGFloat = 0, left: CGFloat = 0, bottom: CGFloat = 0, right: CGFloat = 0, multiplier: CGFloat = 1) -> Layout {
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, multiplier: multiplier)
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 {
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, multiplier: multiplier)
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 {
public func top(_ top: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return self.top(v, top: top, multiplier: multiplier)
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 {
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, multiplier: multiplier)
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 {
public func left(_ left: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return self.left(v, left: left, multiplier: multiplier)
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 {
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, multiplier: multiplier)
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 {
public func bottom(_ bottom: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return self.bottom(v, bottom: bottom, multiplier: multiplier)
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 {
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, multiplier: multiplier)
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 {
public func right(_ right: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return self.right(v, right: right, multiplier: multiplier)
return self.right(v, right: right)
}
/**
......@@ -419,15 +397,14 @@ public class Layout {
- 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 {
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, multiplier: multiplier)
Layout.topLeft(parent: v, child: child, top: top, left: left)
return self
}
......@@ -435,14 +412,13 @@ public class Layout {
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 {
public func topLeft(top: CGFloat = 0, left: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return topLeft(v, top: top, left: left, multiplier: multiplier)
return topLeft(v, top: top, left: left)
}
/**
......@@ -450,15 +426,14 @@ public class Layout {
- 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 {
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, multiplier: multiplier)
Layout.topRight(parent: v, child: child, top: top, right: right)
return self
}
......@@ -466,14 +441,13 @@ public class Layout {
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 {
public func topRight(top: CGFloat = 0, right: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return topRight(v, top: top, right: right, multiplier: multiplier)
return topRight(v, top: top, right: right)
}
/**
......@@ -481,15 +455,14 @@ public class Layout {
- 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 {
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, multiplier: multiplier)
Layout.bottomLeft(parent: v, child: child, bottom: bottom, left: left)
return self
}
......@@ -497,14 +470,13 @@ public class Layout {
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 {
public func bottomLeft(bottom: CGFloat = 0, left: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return bottomLeft(v, bottom: bottom, left: left, multiplier: multiplier)
return bottomLeft(v, bottom: bottom, left: left)
}
/**
......@@ -512,15 +484,14 @@ public class Layout {
- 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 {
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, multiplier: multiplier)
Layout.bottomRight(parent: v, child: child, bottom: bottom, right: right)
return self
}
......@@ -528,14 +499,13 @@ public class Layout {
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 {
public func bottomRight(bottom: CGFloat = 0, right: CGFloat = 0) -> Layout {
guard let v = child else {
return debugChildNotAvailableMessage()
}
return bottomRight(v, bottom: bottom, right: right, multiplier: multiplier)
return bottomRight(v, bottom: bottom, right: right)
}
/**
......@@ -543,15 +513,14 @@ public class Layout {
- 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 {
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)
Layout.center(parent: v, child: child, offsetX: offsetX, offsetY: offsetY)
return self
}
......@@ -559,72 +528,67 @@ public class Layout {
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 {
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)
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 {
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)
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)
}
}
......@@ -634,36 +598,33 @@ 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) {
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: multiplier, constant: width))
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) {
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: multiplier, constant: height))
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)
}
/**
......@@ -674,20 +635,17 @@ 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))
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: 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[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))
}
parent.addConstraint(NSLayoutConstraint(item: children[children.count - 1], attribute: .right, relatedBy: .equal, toItem: parent, attribute: .right, multiplier: multiplier, constant: -right))
}
/**
......@@ -698,20 +656,17 @@ 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))
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: 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[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))
}
parent.addConstraint(NSLayoutConstraint(item: children[children.count - 1], attribute: .bottom, relatedBy: .equal, toItem: parent, attribute: .bottom, multiplier: multiplier, constant: -bottom))
}
/**
......@@ -720,12 +675,11 @@ extension Layout {
- 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) {
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: multiplier, constant: left))
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .right, relatedBy: .equal, toItem: parent, attribute: .right, multiplier: multiplier, constant: -right))
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))
}
/**
......@@ -734,12 +688,11 @@ extension Layout {
- 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) {
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: multiplier, constant: top))
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .bottom, relatedBy: .equal, toItem: parent, attribute: .bottom, multiplier: multiplier, constant: -bottom))
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))
}
/**
......@@ -750,11 +703,10 @@ 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)
}
/**
......@@ -762,12 +714,11 @@ extension Layout {
- 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) {
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: multiplier, constant: top))
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .top, relatedBy: .equal, toItem: parent, attribute: .top, multiplier: 1, constant: top))
}
/**
......@@ -775,12 +726,11 @@ extension Layout {
- 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) {
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: multiplier, constant: left))
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .left, relatedBy: .equal, toItem: parent, attribute: .left, multiplier: 1, constant: left))
}
/**
......@@ -788,12 +738,11 @@ extension Layout {
- 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) {
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: multiplier, constant: -bottom))
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .bottom, relatedBy: .equal, toItem: parent, attribute: .bottom, multiplier: 1, constant: -bottom))
}
/**
......@@ -801,12 +750,11 @@ extension Layout {
- 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) {
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: multiplier, constant: -right))
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .right, relatedBy: .equal, toItem: parent, attribute: .right, multiplier: 1, constant: -right))
}
/**
......@@ -815,12 +763,11 @@ extension Layout {
- 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)
}
/**
......@@ -829,12 +776,11 @@ extension Layout {
- 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)
}
/**
......@@ -843,12 +789,11 @@ extension Layout {
- 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)
}
/**
......@@ -857,12 +802,11 @@ extension Layout {
- 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)
}
/**
......@@ -871,12 +815,11 @@ extension Layout {
- 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)
}
/**
......@@ -884,12 +827,11 @@ extension Layout {
- 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) {
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: multiplier, constant: offset))
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .centerX, relatedBy: .equal, toItem: parent, attribute: .centerX, multiplier: 1, constant: offset))
}
/**
......@@ -897,12 +839,11 @@ extension Layout {
- 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) {
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: multiplier, constant: offset))
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .centerY, relatedBy: .equal, toItem: parent, attribute: .centerY, multiplier: 1, constant: offset))
}
/**
......
......@@ -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