Commit a89ba9a7 by Daniel Dahan

development: updated Divider to use thickness rather than height

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