Commit 4e746a65 by Orkhan Alikhanov

Added leading and trailing support

parent e9006d9e
......@@ -124,6 +124,26 @@ public extension Layout {
}
/**
Constraints leading of the view to its parent's.
- Parameter _ offset: A CGFloat offset.
- Returns: A Layout instance to allow chaining.
*/
@discardableResult
func leading(_ offset: CGFloat = 0) -> Layout {
return constraint(.leading, constant: offset)
}
/**
Constraints trailing of the view to its parent.
- Parameter _ offset: A CGFloat offset.
- Returns: A Layout instance to allow chaining.
*/
@discardableResult
func trailing(_ offset: CGFloat = 0) -> Layout {
return constraint(.trailing, constant: -offset)
}
/**
Constraints bottom of the view to its parent's.
- Parameter _ offset: A CGFloat offset.
- Returns: A Layout instance to allow chaining.
......@@ -189,6 +209,61 @@ public extension Layout {
}
/**
Constraints top-leading of the view to its parent's.
- Parameter top: A CGFloat offset for top.
- Parameter leading: A CGFloat offset for leading.
- Returns: A Layout instance to allow chaining.
*/
@discardableResult
func topLeading(top: CGFloat = 0, leading: CGFloat = 0) -> Layout {
return constraint(.topLeading, constants: top, leading)
}
/**
Constraints top-trailing of the view to its parent's.
- Parameter top: A CGFloat offset for top.
- Parameter trailing: A CGFloat offset for trailing.
- Returns: A Layout instance to allow chaining.
*/
@discardableResult
func topTrailing(top: CGFloat = 0, trailing: CGFloat = 0) -> Layout {
return constraint(.topTrailing, constants: top, -trailing)
}
/**
Constraints bottom-leading of the view to its parent's.
- Parameter bottom: A CGFloat offset for bottom.
- Parameter leading: A CGFloat offset for leading.
- Returns: A Layout instance to allow chaining.
*/
@discardableResult
func bottomLeading(bottom: CGFloat = 0, leading: CGFloat = 0) -> Layout {
return constraint(.bottomLeading, constants: -bottom, leading)
}
/**
Constraints bottom-trailing of the view to its parent's.
- Parameter bottom: A CGFloat offset for bottom.
- Parameter trailing: A CGFloat offset for trailing.
- Returns: A Layout instance to allow chaining.
*/
@discardableResult
func bottomTrailing(bottom: CGFloat = 0, trailing: CGFloat = 0) -> Layout {
return constraint(.bottomTrailing, constants: -bottom, -trailing)
}
/**
Constraints leading and trailing of the view to its parent's.
- Parameter leading: A CGFloat offset for leading.
- Parameter trailing: A CGFloat offset for trailing.
- Returns: A Layout instance to allow chaining.
*/
@discardableResult
func leadingTrailing(leading: CGFloat = 0, trailing: CGFloat = 0) -> Layout {
return constraint(.leadingTrailing, constants: leading, -trailing)
}
/**
Constraints top and bottom of the view to its parent's.
- Parameter top: A CGFloat offset for top.
- Parameter bottom: A CGFloat offset for bottom.
......@@ -321,6 +396,28 @@ public extension Layout {
}
/**
Constraints leading of the view to the given anchor.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ offset: A CGFloat offset.
- Returns: A Layout instance to allow chaining.
*/
@discardableResult
func leading(_ anchor: LayoutAnchorable, _ offset: CGFloat = 0) -> Layout {
return constraint(.leading, to: anchor, constant: offset)
}
/**
Constraints trailing of the view to the given anchor.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ offset: A CGFloat offset.
- Returns: A Layout instance to allow chaining.
*/
@discardableResult
func trailing(_ anchor: LayoutAnchorable, _ offset: CGFloat = 0) -> Layout {
return constraint(.trailing, to: anchor, constant: -offset)
}
/**
Constraints bottom of the view to the given anchor.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ offset: A CGFloat offset.
......@@ -332,6 +429,66 @@ public extension Layout {
}
/**
Constraints top-leading of the view to the given anchor.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter top: A CGFloat offset for top.
- Parameter leading: A CGFloat offset for leading.
- Returns: A Layout instance to allow chaining.
*/
@discardableResult
func topLeading(_ anchor: LayoutAnchorable, top: CGFloat = 0, leading: CGFloat = 0) -> Layout {
return constraint(.topLeading, to: anchor, constants: top, leading)
}
/**
Constraints top-trailing of the view to the given anchor.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter top: A CGFloat offset for top.
- Parameter trailing: A CGFloat offset for trailing.
- Returns: A Layout instance to allow chaining.
*/
@discardableResult
func topTrailing(_ anchor: LayoutAnchorable, top: CGFloat = 0, trailing: CGFloat = 0) -> Layout {
return constraint(.topTrailing, to: anchor, constants: top, -trailing)
}
/**
Constraints bottom-leading of the view to the given anchor.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter bottom: A CGFloat offset for bottom.
- Parameter leading: A CGFloat offset for leading.
- Returns: A Layout instance to allow chaining.
*/
@discardableResult
func bottomLeading(_ anchor: LayoutAnchorable, bottom: CGFloat = 0, leading: CGFloat = 0) -> Layout {
return constraint(.bottomLeading, to: anchor, constants: -bottom, leading)
}
/**
Constraints bottom-trailing of the view to the given anchor.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter bottom: A CGFloat offset for bottom.
- Parameter trailing: A CGFloat offset for trailing.
- Returns: A Layout instance to allow chaining.
*/
@discardableResult
func bottomTrailing(_ anchor: LayoutAnchorable, bottom: CGFloat = 0, trailing: CGFloat = 0) -> Layout {
return constraint(.bottomTrailing, to: anchor, constants: -bottom, -trailing)
}
/**
Constraints leading and trailing of the view to the given anchor.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter leading: A CGFloat offset for leading.
- Parameter trailing: A CGFloat offset for trailing.
- Returns: A Layout instance to allow chaining.
*/
@discardableResult
func leadingTrailing(_ anchor: LayoutAnchorable, leading: CGFloat = 0, trailing: CGFloat = 0) -> Layout {
return constraint(.leadingTrailing, to: anchor, constants: leading, -trailing)
}
/**
Constraints top-left of the view to the given anchor.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter top: A CGFloat offset for top.
......
......@@ -76,6 +76,16 @@ public extension LayoutAnchor {
return anchor(.right)
}
/// A layout anchor representing leading of the view.
var leading: LayoutAnchor {
return anchor(.leading)
}
/// A layout anchor representing trailing of the view.
var trailing: LayoutAnchor {
return anchor(.trailing)
}
/// A layout anchor representing top-left of the view.
var topLeft: LayoutAnchor {
return acnhor(.topLeft)
......@@ -96,6 +106,26 @@ public extension LayoutAnchor {
return acnhor(.bottomRight)
}
/// A layout anchor representing top-leading of the view.
var topLeading: LayoutAnchor {
return acnhor(.topLeading)
}
/// A layout anchor representing top-trailing of the view.
var topTrailing: LayoutAnchor {
return acnhor(.topTrailing)
}
/// A layout anchor representing bottom-leading of the view.
var bottomLeading: LayoutAnchor {
return acnhor(.bottomLeading)
}
/// A layout anchor representing bottom-trailing of the view.
var bottomTrailing: LayoutAnchor {
return acnhor(.bottomTrailing)
}
/// A layout anchor representing top and bottom of the view.
var topBottom: LayoutAnchor {
return acnhor(.topBottom)
......@@ -106,6 +136,11 @@ public extension LayoutAnchor {
return acnhor(.leftRight)
}
/// A layout anchor representing leading and trailing of the view.
var leadingTrailing: LayoutAnchor {
return acnhor(.leadingTrailing)
}
/// A layout anchor representing center of the view.
var center: LayoutAnchor {
return acnhor(.center)
......
......@@ -59,6 +59,31 @@ internal extension Array where Element == LayoutAttribute {
return [.left, .right]
}
/// A LayoutAttribute array containing top and leading.
static var topLeading: [LayoutAttribute] {
return [.top, .leading]
}
/// A LayoutAttribute array containing top and trailing.
static var topTrailing: [LayoutAttribute] {
return [.top, .trailing]
}
/// A LayoutAttribute array containing bottom and leading.
static var bottomLeading: [LayoutAttribute] {
return [.bottom, .leading]
}
/// A LayoutAttribute array containing bottom and trailing.
static var bottomTrailing: [LayoutAttribute] {
return [.bottom, .trailing]
}
/// A LayoutAttribute array containing left and trailing.
static var leadingTrailing: [LayoutAttribute] {
return [.leading, .trailing]
}
/// A LayoutAttribute array containing top and bottom.
static var topBottom: [LayoutAttribute] {
return [.top, .bottom]
......
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