UILab is a simple group of extension framework designed to streamline and simplify the process of setting constraints in Swift-based UIKit projects for personal usage.
Integrate UILab into your project using your preferred dependency manager (Swift Package Manager, CocoaPods, or Manuel). Detailed installation instructions can be found in the further in the Readme.
UILab is available through SPM. To Install it
https://github.com/yasinkbas/UILab
You can also manually integrate UILab into your project by downloading it from here.
UILab no longer supports Cocoapods, but you can still use the latest version 0.3.2
on Cocoapods.
To install it, add the following line to your Podfile:
pod 'UILab'
Begin creating constraints using the concise and expressive syntax provided by UILab. Whether you're working with views, labels, buttons, or any other UI element, UILab aims to simplify the process.
You can use UILab as a matter of your taste. There are 3 ways to set constraints.
class ViewController: UIViewController {
private lazy var containerView = UIView()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(containerView)
containerView.set(.center(view), .width(100), .height(100))
}
}
class ViewController: UIViewController {
private lazy var containerView = UIView()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(containerView)
var containerViewConstraints = containerView[.center(view), .width(100), .height(100)]
containerViewConstraints.commit = true // activate
}
}
Note: When using subscript style, you must set commit true to activate it.
class ViewController: UIViewController {
private lazy var containerView = UIView()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(containerView)
containerView.set {
ConstraintType.center(view, x: 9, y: 9)
ConstraintType.width(100)
ConstraintType.height(100)
}
}
}
You can check all the available constraint types under ConstraintType
here.
You can save for later your constraints before committing or retrieve them easily with get
function.
var contraintsYouWannaHold: Constraints?
func setup() {
contraintsYouWannaHold = myView[.center(anotherView), .width(100), .height(100)]
contraintsYouWannaHold?.commit = true // set true, when you want to activate it
}
let myViewHeightAnchor = myView.get(.height).first
To help you grasp the simplicity and power of UILab, let's delve into a few practical examples showcasing how to set constraints for common UI scenarios in example project.
Note: To run the example project, clone the repo, and run pod install
from the Example directory first.
UILab is created for personal usage, but all contributions are welcome.
UILab is available under the MIT license. See the LICENSE file for more info.
link |
Stars: 1 |
Last commit: 30 weeks ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics