LayItOut
The layout of any view hierarchy can be defined as a series of linear equations that has one and only one possible solution. LayItOut make you easily to declare equations.
Requirements
- iOS 9.0+ / tvOS 9.0+ / macOS 10.11+
- Xcode 9.3+
- Swift 4.1+
Usage
-
Sample
Equations by LayItOut:
// ①
purpleView.area.left == superView.marginedArea.left
// ④
purpleView.area.top == superView.marginedArea.top + 60
// ②
purpleView.area.right == orangeView.area.left - 20
// ⑤
orangeView.area.top == superView.marginedArea.top + 60
// ③
orangeView.area.right == superView.marginedArea.right
// ⑦
orangeView.area.bottom == superView.marginedArea.bottom - 60
// ⑥
purpleView.area.bottom == superView.marginedArea.bottom - 60
// ⑧
purpleView.area.width == orangeView.area.width * 0.5
My preferred way:
// ① & ④
purpleView.area.upperLeft == superView.marginedArea.upperLeft + CGPoint(x: 0, y: 60)
// ② & new ⑤
purpleView.area.upperRight == orangeView.area.upperLeft - CGPoint(x: 20, y: 0)
// ③ & ⑦
orangeView.area.lowerRight == superView.marginedArea.lowerRight - CGPoint(x: 0, y: 60)
// ⑥
purpleView.area.bottom == superView.marginedArea.bottom - 60
// ⑧
purpleView.area.width == orangeView.area.width * 0.5
The coordinate system in iOS has its origin at the upper left of the drawing area, and positive values extend down and to the right from it.
-
Areas of view
Area | Description | Note |
---|---|---|
area: Area | The view's frame | |
marginedArea: SArea | The view’s margins | only in iOS, tvOS |
readableArea: SArea | The area with a readable width within the view | only in iOS, tvOS |
safeArea: SArea | The area unobscured by bars and other content | only in iOS, tvOS |
-
Items of area
Item | Note |
---|---|
width |
|
height |
|
top |
|
left |
|
bottom |
|
right |
|
centerX |
|
centerY |
|
leading |
|
trailing |
|
firstBaseline |
only in Area |
lastBaseline |
only in Area |
size |
composed of width & height |
center |
composed of centerX & centerY |
upperLeft |
composed of left & top |
upperRight |
composed of right & top |
lowerLeft |
composed of left & bottom |
lowerRight |
composed of right & bottom |
origin |
upperLeft in iOS, tvOS, lowerLeft in macOS |
-
Priority
Specify priority by --
:
view.area.width == 100 -- .defaultLow
-
More
LayItOut based on NSLayoutAnchor. See Auto Layout Guide & NSLayoutAnchor for details.
Installation
To integrate LayItOut into your Xcode project using CocoaPods:
pod 'LayItOut'
License
LayItOut is released under the MIT license. See LICENSE for details.