A collection of convenience properties and extensions for laying out views in UIKit
Spackle is a small framework consisting of a collection of various properties and extensions for making manually laying out views in UIKit a bit more quick and streamlined. It allows quick alignment of views from various points in their frame values, and also has rudimentary support for right-to-left style interfaces.
Instructions
As a very simple use-case, consider how you would lay out this red view inside of its white container view.
It would probably look something like this.
redView.frame.origin.x = containerView.frame.width - (redView.frame.width + 10)
redView.frame.origin.y = containerView.frame.midY - redView.bounds.midY
This is super performant and is very simple to write, but it isn’t very easy to read after the fact.
With Spackle, the equivalent code becomes this.
redView.rightCenter = containerView.bounds.rightCenter.offsetBy(x: -10)
By defining and using relative anchors, we can achieve a similar flexibility to Auto Layout, but in a much simpler way.
Requirements
- Swift 5
- UIKit-compatible platforms (iOS, tvOS, Mac Catalyst)
Installation
Spackle is a very simple framework and can be easily imported manually or with CocoaPods.
Manual Installation
Drag the Spackle
folder into your Xcode project.
CocoaPods
pod 'Spackle'
SPM
I’ll add this eventually. But if you want it now, please file a PR!
Credits
Spackle was built as a component of iComics 2 by Tim Oliver
License
Spackle is available under the MIT License. Please check the LICENSE file for more information.