Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/acecilia/nestlayout
Syntactic sugar for StackViews layout
https://github.com/acecilia/nestlayout
apple layout nest stackview swift swift4 syntactic-sugar uistacklayout uistackview
Last synced: 4 days ago
JSON representation
Syntactic sugar for StackViews layout
- Host: GitHub
- URL: https://github.com/acecilia/nestlayout
- Owner: acecilia
- License: mit
- Created: 2017-10-14T15:19:42.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-15T15:22:27.000Z (almost 7 years ago)
- Last Synced: 2025-01-13T18:15:28.256Z (14 days ago)
- Topics: apple, layout, nest, stackview, swift, swift4, syntactic-sugar, uistacklayout, uistackview
- Language: Swift
- Size: 109 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NestLayout
#### Syntactic sugar for StackViews layoutYet, 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):```swift
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
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](https://github.com/acecilia/SugarEdges).## Installation
NestLayout is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
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.