All Projects → evan-liu → FormationLayout

evan-liu / FormationLayout

Licence: MIT license
Yet Another Swift Auto Layout DSL

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to FormationLayout

Automatic Height Tagcells
This is a sample project to implement features with dynamic height of UITableViewCell based on autolayout, tags aligned automatically and clickable tags.
Stars: ✭ 229 (+332.08%)
Mutual labels:  autolayout
StackableTableView
A UITableView subclass that enables setting an array of views for both headers and footers utilizing UIStackView
Stars: ✭ 72 (+35.85%)
Mutual labels:  autolayout
JXLayerAutoLayout
优雅的实现CALayer AutoLayout
Stars: ✭ 19 (-64.15%)
Mutual labels:  autolayout
SDCAutoLayout
A UIView category that simplifies dealing with Auto Layout
Stars: ✭ 23 (-56.6%)
Mutual labels:  autolayout
SideMenuSwiftDemo
SideMenu in Swift with autolayout
Stars: ✭ 79 (+49.06%)
Mutual labels:  autolayout
VanillaConstraints
🍦 Simplified and chainable AutoLayout constraints for iOS.
Stars: ✭ 42 (-20.75%)
Mutual labels:  autolayout
Core Layout
Flexbox & CSS-style Layout in Swift.
Stars: ✭ 215 (+305.66%)
Mutual labels:  autolayout
swift-boilerplate
Clean Architecture for iOS projects (Swift + Programmatically UI + MVC + RxSwift + Auto Layout Visual Format + REST + JWT)
Stars: ✭ 14 (-73.58%)
Mutual labels:  autolayout
GoneVisible
GoneVisible is a UIView extension that uses AutoLayout to add "gone" state like Android.
Stars: ✭ 27 (-49.06%)
Mutual labels:  autolayout
Cassowary
High performance swift implement of constraint solving algorithm cassowary
Stars: ✭ 45 (-15.09%)
Mutual labels:  autolayout
StoryboardConstraint
A simple way to use programmatically Autolayout Constraint created in Storyboard.
Stars: ✭ 25 (-52.83%)
Mutual labels:  autolayout
iOSProjects
It's project that contains different applications developed with Swift 5.7 👨‍💻👩🏼‍💻🧑🏿‍💻
Stars: ✭ 122 (+130.19%)
Mutual labels:  autolayout
Driftwood
Driftwood is a DSL to make Auto Layout easy on iOS, tvOS and macOS.
Stars: ✭ 14 (-73.58%)
Mutual labels:  autolayout
Ragrid
Intrinsic first auto-layout flexbox grid
Stars: ✭ 249 (+369.81%)
Mutual labels:  autolayout
WHC Layout
Swift iOS and Mac OS X platforms currently in use the fastest the simplest development to build the UI layout automatically open source library, strong dynamic layout constraint handling capacity,iOS/Mac OS X平台上目前使用最简单开发构建UI速度最快的自动布局开源库,强悍的动态布局约束处理能力
Stars: ✭ 56 (+5.66%)
Mutual labels:  autolayout
Fluid For Sketch
[Sketch Plugin] Sketch-flavored Auto Layout-like Constraints
Stars: ✭ 2,408 (+4443.4%)
Mutual labels:  autolayout
Constrainable
simple declarative autolayout µframework based on Swift 4 KeyPath
Stars: ✭ 26 (-50.94%)
Mutual labels:  autolayout
wwlayout
Swifty DSL for programmatic Auto Layout in iOS
Stars: ✭ 46 (-13.21%)
Mutual labels:  autolayout
ios ui recipe showcase
iOSアプリ開発 - UI実装であると嬉しいレシピブック掲載サンプル
Stars: ✭ 54 (+1.89%)
Mutual labels:  autolayout
UseAutoLayout
UseAutoLayout @propertyWrapper for Swift
Stars: ✭ 25 (-52.83%)
Mutual labels:  autolayout

FormationLayout

banner

Platform License CocoaPods Carthage

Documentation

FormationLayout is the top level layout class for one root view.

  • FormationLayout takes a UIView as its rootView.
  • translatesAutoresizingMaskIntoConstraints of rootView is not set to false by default but can be set in constructor.
  • translatesAutoresizingMaskIntoConstraints of subviews will be set to false automaticly.
  • Subviews with no superView will be added to rootView automaticly.
demo { canvas, icon in
    FormationLayout(rootView: canvas)[icon].center(equalTo: canvas)
}

FormationLayout

Anchors

View anchors: left, right, top, bottom, leading, trailing, width, height, centerX, centerY, lastBaseline, firstBaseline, centerXWithinMargins, centerYWithinMargins

  • layout[view].anchor(equalTo: view2, multiplyBy: multiplier, plus: constant)
    • view.anchor == view2.anchor * multiplier + constant
  • layout[view].anchor(equalTo: anchor2, of: view2, multiplyBy: multiplier, minus: constant)
    • view.anchor == view2.anchor2 * multiplier - constant
  • layout[view].anchor(greaterThanOrEqualTo: view2)
    • view.anchor >= view2.anchor
  • layout[view].anchor(lessThanOrEqualTo: value) (Only width and height)
    • view.anchor <= value
demo { canvas, icon1, icon2, icon3 in
    let layout = FormationLayout(rootView: canvas)
    layout[icon1].top(equalTo: canvas, plus: 10).leading(equalTo: canvas, plus: 20)
    layout[icon2].top(equalTo: icon1).leading(equalTo: .trailing, of: icon1, plus: 10)
    layout[icon3].bottom(equalTo: canvas, minus: 10).leading(equalTo: icon1, multiplyBy: 2)
}

Anchors

Helpers

  • aspectRatio: width:height
  • size: width & height
  • center: centerX & centerY
demo { canvas, icon1, icon2, icon3 in
    let layout = FormationLayout(rootView: canvas)
    layout[icon1].aspectRatio(equalTo: 1.5).width(equalTo: 30)
    layout[icon2].size(equalTo: 30).center(equalTo: canvas, multiplyBy: 0.8)
    layout[icon3].size(equalTo: icon2, minus: 10).center(equalTo: icon2, plus: 30)
}

Helpers

Pin

layout[view].pin(to: canvas) will set

  • view.top == canvas.top
  • view.bottom == canvas.bottom
  • view.left == canvas.left
  • view.right == canvas.right

layout[view].pin(to: canvas, margin: 10) will set

  • view.top == canvas.top + 10
  • view.bottom == canvas.bottom - 10
  • view.left == canvas.left + 10
  • view.right == canvas.right - 10
demo { canvas, icon1, icon2, icon3 in
    let layout = FormationLayout(rootView: canvas)
    layout[icon1].pin(to: canvas, edgesWithMargin: [.top: 10, .leading: 3])
    layout[icon2].pin(to: canvas, margin: 30)
    layout[icon3].pin(to: canvas, edges: [.topBottom, .trailing], margin: 3)
}

Pin

Abreast

  • layout[logo].below(topLayoutGuide, gap: 10)
    • logo.top == topLayoutGuide.bottom + 10
  • layout[copyright].above(bottomLayoutGuide, gap: 10)
    • copyright.bottom == bottomLayoutGuide.top - 10
demo { canvas, icon1, icon2, icon3 in
    let layout = FormationLayout(rootView: canvas)
    layout[icon1].center(equalTo: canvas)
    layout[icon2].before(icon1).above(icon1, gap: 5)
    layout[icon3].after(icon1).below(icon1, gap: 5)
}

Abreast

Group

layout.group(view1, view2) will create same constraints for

  • layout[view1]
  • layout[view2]
demo { canvas, icon1, icon2, icon3 in
    let layout = FormationLayout(rootView: canvas)
    layout.group(icon1, icon2, icon3).centerY(equalTo: canvas)
    layout[icon1].leading(equalTo: canvas, plus: 5)
    layout[icon2].centerX(equalTo: canvas)
    layout[icon3].trailing(equalTo: canvas, minus: 5)
}

Group

Condition

layout.when() creates constraints for one condition and its not creates constrains for otherwise.

demo { canvas, icon in
    var isLoggedIn = true 
    
    let layout = FormationLayout(rootView: canvas)
    let loggedInLayout = layout.when { isLoggedIn }
    
    layout[icon].centerX(equalTo: canvas)
    loggedInLayout[icon].top(equalTo: canvas, plus: 10)
    loggedInLayout.not[icon].bottom(equalTo: canvas, minus: 10)
    
    layout.update()
}

Condition

isLoggedIn = false

ConditionNot

Priority

All constraints have UILayoutPriorityRequired by default.

demo { canvas, icon in
    let layout = FormationLayout(rootView: canvas)
    layout[icon].centerX(equalTo: canvas).size(equalTo: 20)
        .centerY(equalTo: canvas, at: UILayoutPriorityDefaultLow) // Try UILayoutPriorityRequired
        .bottom(equalTo: canvas, at: UILayoutPriorityDefaultHigh)
}

PriorityLow

UILayoutPriorityRequired:

PriorityRequired

Playground

  • Open Documentation/Doc.xcworkspace.
  • Build the FormationLayout-iOS scheme (⌘+B).
  • Open Doc playground in the Project navigator.
  • Click "Show Result" button at the most right side of each demo line.

Install

CocoaPods

pod 'FormationLayout', '~> 0.8.5'

Carthage

github "evan-liu/FormationLayout" >= 0.8.5
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].