ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - banjun/NorthLayout: The fast path to autolayout views in code
The fast path to autolayout views in code. Contribute to banjun/NorthLayout development by creating an account on GitHub.
Visit Site

GitHub - banjun/NorthLayout: The fast path to autolayout views in code

GitHub - banjun/NorthLayout: The fast path to autolayout views in code

NorthLayout

Build Status CI Version License Platform

The fast path to autolayout views in code

Talks

https://speakerdeck.com/banjun/auto-layout-with-an-extended-visual-format-language at AltConf19 https://speakerdeck.com/banjun/lets-start-vfl

Simple Usage

let iconView = UIImageView() // and customize...
let nameLabel = UILabel() // and customize...

override func loadView() {
    super.loadView()
    title = "Simple Example"
    view.backgroundColor = .white
    let autolayout = northLayoutFormat(["p": 8], [
        "icon": iconView,
        "name": nameLabel])
    autolayout("H:||[icon(==64)]") // 64pt width icon on left side with default margin
    autolayout("H:||[name]||") // full width label with default margin
    autolayout("V:||-p-[icon(==64)]-p-[name]") // stack them vertically
}

See also Example project.

View Level Safe Area Example

override init(frame: CGRect) {
    super.init(frame: frame)
    // autolayout respecting safe area without reference to container view controller
    let autolayout = northLayoutFormat([:], [
        "icon": iconView,
        "name": nameLabel])
    autolayout("H:||-(>=0)-[icon(==64)]-(>=0)-||") // 64pt fitting width icon with default margin
    autolayout("H:||[name]||") // fitting width label with default margin
    autolayout("V:||[icon(==64)]-[name]||") // stack them vertically
    // constrain iconView horizontal ambiguity to safe area center
    layoutMarginsGuide.centerXAnchor.constraint(equalTo: iconView.centerXAnchor).isActive = true
}

See also Example project.

Advanced Example

See Example project.

Features

📜 No Storyboards Required

Let's autolayout in code. boilerplates such as translatesAutoresizingMaskIntoConstraints = false and adding as subview are coded in northLayoutFormat().

↔️ Visual Format Language

Use Visual Format Language (VFL) for layout.

Auto Layout Guide: Visual Format Language

⏸ Extended Visual Format for Layout Margins & Safe Area

In addition to Apple VFL above, NorthLayout introduces || syntax for layout margin bounds.

// stick to side edges (i.e. screen edges for view of view controller)
autolayout("H:|[icon1]|")

// stick to side layout margins (avoids non safe areas)
autolayout("H:||[icon2]||")

📚 View Controller level & View level layout

In autolayout, there is some differences in view of view controller and independent view. northLayoutFormat is available for view controller and view. You can use | as topLayoutGuide or bottomLayoutGuide (mainly for before iOS 11) and avoid conflicting scroll adjustments on view controllers. You can also code layout simply without a view controller on views.

📱🖥 iOS & macOS

Available for UIView & NSView

Migration to NorthLayout 5

NorthLayout 4 has supported Safe Area by translating | bounds as safe area layout guides by default.

NorthLayout 5 adds breaking changes that introduces || layout margin guides and thus | no longer respects Safe Area. Choose | to stick to edges, or || to inset in layout margins or safe area.

Installation

NorthLayout is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "NorthLayout"

Code Snippets

Code snippets help writing VFL activated in string literal scope.

cd (NorthLayout directory)
cp CodeSnippets/*.codesnippet ~/Library/Developer/Xcode/UserData/CodeSnippets/

The Name

NorthLayout is named after where it was cocoapodized, Lake Toya in the North prefecture of Japan, the setting of Celestial Method.

License

NorthLayout is available under the MIT license. See the LICENSE file for more info.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory