diff --git a/Source/Stevia+Constraints.swift b/Source/Stevia+Constraints.swift index 5e33923e..71d946b5 100644 --- a/Source/Stevia+Constraints.swift +++ b/Source/Stevia+Constraints.swift @@ -12,46 +12,6 @@ import UIKit public extension UIView { - @available(*, deprecated: 2.2.1, message: "Use 'addConstraint' instead") - /** - Helper for creating and adding NSLayoutConstraint but with default values provided. - - For instance - - c(item: view1, attribute: .CenterX, toItem: view2) - - is equivalent to - - addConstraint( - NSLayoutConstraint(item: view1, - attribute: .CenterX, - relatedBy: .Equal, - toItem: view2, - attribute: .CenterX, - multiplier: 1, - constant: 0 - ) - ) - - - Returns: The NSLayoutConstraint created. - */ - @discardableResult - public func c(item view1: AnyObject, - attribute attr1: NSLayoutConstraint.Attribute, - relatedBy: NSLayoutConstraint.Relation = .equal, - toItem view2: AnyObject? = nil, - attribute attr2: NSLayoutConstraint.Attribute? = nil, - multiplier: CGFloat = 1, - constant: CGFloat = 0) -> NSLayoutConstraint { - let c = constraint( - item: view1, attribute: attr1, - relatedBy: relatedBy, - toItem: view2, attribute: attr2, - multiplier: multiplier, constant: constant) - addConstraint(c) - return c - } - /** Helper for creating and adding NSLayoutConstraint but with default values provided. diff --git a/Source/Stevia+Stacks.swift b/Source/Stevia+Stacks.swift index 2dbca8b7..23820ebc 100644 --- a/Source/Stevia+Stacks.swift +++ b/Source/Stevia+Stacks.swift @@ -9,9 +9,9 @@ import UIKit public extension UIView { - - /** + /** + Lays out the views on both axis. Note that this is not needed for Horizontal only layouts. @@ -21,13 +21,13 @@ public extension UIView { ``` layout( - 100, - |-email-| ~ 80, - 8, - |-password-forgot-| ~ 80, - >=20, - |login| ~ 80, - 0 + 100, + |-email-| ~ 80, + 8, + |-password-forgot-| ~ 80, + >=20, + |login| ~ 80, + 0 ) ``` */ @@ -40,10 +40,10 @@ public extension UIView { public func layout(_ objects: [Any]) -> [UIView] { var previousMargin: CGFloat? var previousFlexibleMargin: SteviaFlexibleMargin? + for (i, o) in objects.enumerated() { - switch o { - case let v as UIView: + func viewLogic(_ v: UIView) { if let pm = previousMargin { if i == 1 { v.top(pm) // only if first view @@ -79,6 +79,11 @@ public extension UIView { } else { tryStackViewVerticallyWithPreviousView(v, index: i, objects: objects) } + } + + switch o { + case let v as UIView: + viewLogic(v) case is Int, is Double, is CGFloat: let m = cgFloatMarginFromObject(o) previousMargin = m // Store margin for next pass @@ -103,42 +108,8 @@ public extension UIView { case _ as String:() //Do nothin' ! case let a as [UIView]: align(horizontally: a) - let v = a.first! - if let pm = previousMargin { - if i == 1 { - v.top(pm) // only if first view - } else { - if let vx = objects[i-2] as? UIView { - vx.stackV(m: pm, v: v) - } else if let va = objects[i-2] as? [UIView] { - va.first!.stackV(m: pm, v: v) - } - } - previousMargin = nil - } else if let pfm = previousFlexibleMargin { - if i == 1 { - v.top(pfm) // only if first view - } else { - if let vx = objects[i-2] as? UIView { - addConstraint( - item: v, attribute: .top, - relatedBy: pfm.relation, - toItem: vx, attribute: .bottom, - multiplier: 1, constant: pfm.points - ) - } else if let va = objects[i-2] as? [UIView] { - addConstraint( - item: v, attribute: .top, - relatedBy: pfm.relation, - toItem: va.first!, attribute: .bottom, - multiplier: 1, constant: pfm.points - ) - } - } - previousFlexibleMargin = nil - } else { - tryStackViewVerticallyWithPreviousView(v, index: i, objects: objects) - } + let v = a.first! + viewLogic(v) default: () } }