CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.

LayItOut 1.0.0

LayItOut 1.0.0

Maintained by ZZYCN.



LayItOut 1.0.0

  • By
  • ZZYCN

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.