Commit a89ba9a7 by Daniel Dahan

development: updated Divider to use thickness rather than height

parent f7279fc6
......@@ -46,7 +46,7 @@ open class Divider {
internal var line: UIView?
/// A reference to the height.
open var height: CGFloat
open var thickness: CGFloat
/// A preset wrapper around contentEdgeInsets.
open var contentEdgeInsetsPreset = EdgeInsetsPreset.none {
......@@ -93,14 +93,15 @@ open class Divider {
/**
Initializer that takes in a UIView.
- Parameter view: A UIView reference.
- Parameter thickness: A CGFloat value.
*/
internal init(view: UIView?, height: CGFloat = 1) {
internal init(view: UIView?, thickness: CGFloat = 1) {
self.view = view
self.height = height
self.thickness = thickness
}
/// Lays out the divider.
internal func reload() {
open func reload() {
guard let l = line, let v = view else {
return
}
......@@ -109,13 +110,13 @@ open class Divider {
switch alignment {
case .top:
l.frame = CGRect(x: c.left, y: c.top, width: v.width - c.left - c.right, height: height - c.top - c.bottom)
l.frame = CGRect(x: c.left, y: c.top, width: v.width - c.left - c.right, height: thickness)
case .bottom:
l.frame = CGRect(x: c.left, y: v.height - height - c.bottom, width: v.width - c.left - c.right, height: height - c.top - c.bottom)
l.frame = CGRect(x: c.left, y: v.height - thickness - c.bottom, width: v.width - c.left - c.right, height: thickness)
case .left:
l.frame = CGRect(x: c.left, y: c.top, width: height, height: v.height - c.top - c.bottom)
l.frame = CGRect(x: c.left, y: c.top, width: thickness, height: v.height - c.top - c.bottom)
case .right:
l.frame = CGRect(x: v.width - height - c.right, y: c.top, width: height, height: v.height - c.top - c.bottom)
l.frame = CGRect(x: v.width - thickness - c.right, y: c.top, width: thickness, height: v.height - c.top - c.bottom)
}
}
}
......@@ -157,15 +158,14 @@ extension UIView {
}
}
/// Divider height.
/// Divider thickness.
@IBInspectable
open var dividerHeight: CGFloat {
open var dividerThickness: CGFloat {
get {
return divider.height
return divider.thickness
}
set(value) {
divider.height = value
divider.thickness = value
}
}
}
......@@ -223,56 +223,56 @@ public class Grid {
var n: Int = 0
var i: Int = 0
for child in views {
for v in views {
guard let canvas = context else {
return
}
if canvas != child.superview {
child.removeFromSuperview()
canvas.addSubview(child)
if canvas != v.superview {
v.removeFromSuperview()
canvas.addSubview(v)
}
// Forces the views to adjust accordingly to size changes, ie: UILabel.
(child as? UILabel)?.sizeToFit()
(v as? UILabel)?.sizeToFit()
switch axis.direction {
case .horizontal:
let c = 0 == child.grid.columns ? axis.columns / count : child.grid.columns
let co = child.grid.offset.columns
let c = 0 == v.grid.columns ? axis.columns / count : v.grid.columns
let co = v.grid.offset.columns
let w = (canvas.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right + interimSpace) / CGFloat(axis.columns)
child.x = CGFloat(i + n + co) * w + contentEdgeInsets.left + layoutEdgeInsets.left
child.y = contentEdgeInsets.top + layoutEdgeInsets.top
child.width = w * CGFloat(c) - interimSpace
child.height = canvas.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom
v.x = CGFloat(i + n + co) * w + contentEdgeInsets.left + layoutEdgeInsets.left
v.y = contentEdgeInsets.top + layoutEdgeInsets.top
v.width = w * CGFloat(c) - interimSpace
v.height = canvas.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom
n += c + co - 1
case .vertical:
let r = 0 == child.grid.rows ? axis.rows / count : child.grid.rows
let ro = child.grid.offset.rows
let r = 0 == v.grid.rows ? axis.rows / count : v.grid.rows
let ro = v.grid.offset.rows
let h = (canvas.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom + interimSpace) / CGFloat(axis.rows)
child.x = contentEdgeInsets.left + layoutEdgeInsets.left
child.y = CGFloat(i + n + ro) * h + contentEdgeInsets.top + layoutEdgeInsets.top
child.width = canvas.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right
child.height = h * CGFloat(r) - interimSpace
v.x = contentEdgeInsets.left + layoutEdgeInsets.left
v.y = CGFloat(i + n + ro) * h + contentEdgeInsets.top + layoutEdgeInsets.top
v.width = canvas.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right
v.height = h * CGFloat(r) - interimSpace
n += r + ro - 1
case .any:
let r = 0 == child.grid.rows ? axis.rows / count : child.grid.rows
let ro = child.grid.offset.rows
let c = 0 == child.grid.columns ? axis.columns / count : child.grid.columns
let co = child.grid.offset.columns
let r = 0 == v.grid.rows ? axis.rows / count : v.grid.rows
let ro = v.grid.offset.rows
let c = 0 == v.grid.columns ? axis.columns / count : v.grid.columns
let co = v.grid.offset.columns
let w = (canvas.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right + interimSpace) / CGFloat(axis.columns)
let h = (canvas.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom + interimSpace) / CGFloat(axis.rows)
child.x = CGFloat(co) * w + contentEdgeInsets.left + layoutEdgeInsets.left
child.y = CGFloat(ro) * h + contentEdgeInsets.top + layoutEdgeInsets.top
child.width = w * CGFloat(c) - interimSpace
child.height = h * CGFloat(r) - interimSpace
v.x = CGFloat(co) * w + contentEdgeInsets.left + layoutEdgeInsets.left
v.y = CGFloat(ro) * h + contentEdgeInsets.top + layoutEdgeInsets.top
v.width = w * CGFloat(c) - interimSpace
v.height = h * CGFloat(r) - interimSpace
}
i += 1
......
......@@ -489,13 +489,13 @@ open class TextField: UITextField {
/// The animation for the divider when editing begins.
open func dividerEditingDidBeginAnimation() {
dividerHeight = dividerActiveHeight
dividerThickness = dividerActiveHeight
dividerColor = dividerActiveColor
}
/// The animation for the divider when editing ends.
open func dividerEditingDidEndAnimation() {
dividerHeight = dividerNormalHeight
dividerThickness = dividerNormalHeight
dividerColor = dividerNormalColor
}
......
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