Latest 0.4.0
Homepage https://github.com/acecilia/NestLayout
License MIT
Platforms ios 9.0
Frameworks UIKit
Authors

Syntactic sugar for StackViews layout

Yet, another autolayout framework. Why is this different?

In iOS9 Apple introduced StackViews as an easier, safer, more effective and more flexible way of configuring the layout (they are great ;P). But, after using them for a long time I find them too verbose, requiring several lines of code when I want to perform a simple layout change that is a bit more elaborated than usual. In the end, when the view layout grows in length and complexity, such an amount of unordered lines of code is prone to bugs, and difficult to read.

This framework makes exclusive use of StackViews for configuring the layout: basically you can see it as syntactic sugar for StackView based layouts. the benefits are:

  • The layout logic is implemented by Apple and the UIStackView class (AutoLayout is working behind the scenes), not a third party developer. This means that it is reliable in terms of good performance and minimal implementation bugs.
  • The API exposed by this framework will not change as long as the API exposed by UIStackView does not change. This means that it is reliable in terms of long-term maintainability.
  • The API exposed by this framework is exacly the same as the one exposed by the UIStackView class. This means that it has a minimal learning curve, and together with autocompletion is super discoverable and easy to use.
  • The source code of this framework is under 200 lines: nothing to worry about if you do not feel confortable about adding another dependency to your project.
  • The API exposed by this framework keeps your code tidy, easier to read and more expressive. In the end, less prone to bugs.

Usage

hFixed corresponds to views with height constraint (in red color). hwFixed corresponds to views with height and width constraints (in orange color):

UIStackView(hFixedView1, axis: .vertical, spacing: 10)
    .nest(label, alignment: .center)
    .nest(alignment: .center) {
        $0.nest(hwFixedView1, hwFixedView2, axis: .horizontal, alignment: .top)
    }
    .nest(hFixedView2, margins: [.left + .right: 30]) // This way of setting the margins is provided by the framework SugarEdges
    .snapEdges(in: contentView)

The result:

Example

Example

To run the example project, clone the repo, and open the workspace found under the Example folder with Xcode.

Requirements

In order to easily set the margins when using NestLayout, it is recommended (but not mandatory) to also install SugarEdges.

Installation

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

pod 'NestLayout'

Author

Andrés Cecilia Luque (acecilia), [email protected]

License

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

Latest podspec

{
    "name": "NestLayout",
    "version": "0.4.0",
    "summary": "Syntactic sugar for StackViews layout",
    "description": "This framework makes exclusive use of StackViews for configuring the layout: basically you can see it as syntactic sugar for StackView based layouts. the benefits are:nn* The layout logic is implemented by Apple and the StackViews, not a third party developer. This means you can rely on it in terms of performance and implementation bugs.n* The API exposed by this framework will not change as long as the API used by StackViews does not change. This means you can rely on it in terms of long-term maintainability.n* The API exposed by this framework keeps your code tidy, easier to read and more expressive. In the end, less prone to bugs.",
    "homepage": "https://github.com/acecilia/NestLayout",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Andru00e9s Cecilia Luque": "[email protected]"
    },
    "source": {
        "git": "https://github.com/acecilia/NestLayout.git",
        "tag": "0.4.0"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source_files": "Sources/**/*",
    "frameworks": "UIKit"
}

Pin It on Pinterest

Share This