TinyConstraints alternatives and similar libraries
Based on the "Layout" category.
Alternatively, view TinyConstraints alternatives based on common mentions on social networks and blogs.
-
Masonry
Harness the power of AutoLayout NSLayoutConstraints with a simplified, chainable and expressive syntax. Supports iOS and OSX Auto Layout -
FDTemplateLayoutCell
Template auto layout cell for automatically UITableViewCell height calculating -
PureLayout
The ultimate API for iOS & OS X Auto Layout — impressively simple, immensely powerful. Objective-C and Swift compatible. -
Cartography
A declarative Auto Layout DSL for Swift :iphone::triangular_ruler: -
MyLinearLayout
MyLayout is a powerful iOS UI framework implemented by Objective-C. It integrates the functions with Android Layout,iOS AutoLayout,SizeClass, HTML CSS float and flexbox and bootstrap. So you can use LinearLayout,RelativeLayout,FrameLayout,TableLayout,FlowLayout,FloatLayout,PathLayout,GridLayout,LayoutSizeClass to build your App 自动布局 UIView UITableView UICollectionView RTL -
DeviceKit
DeviceKit is a value-type replacement of UIDevice. -
LayoutKit
LayoutKit is a fast view layout library for iOS, macOS, and tvOS. -
PinLayout
Fast Swift Views layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainable. [iOS/macOS/tvOS/CALayer] -
FlexLayout
FlexLayout adds a nice Swift interface to the highly optimized facebook/yoga flexbox implementation. Concise, intuitive & chainable syntax. -
Device
Light weight tool for detecting the current device and screen size written in swift. -
FLKAutoLayout
UIView category which makes it easy to create layout constraints in code -
set-simulator-location
CLI for setting location in the iOS simulator -
Compose
Compose is a library that helps you compose complex and dynamic views. -
Anchorage
A collection of operators and utilities that simplify iOS layout code. -
Relayout
Swift microframework for declaring Auto Layout constraints functionally -
UIDeviceComplete
UIDevice extensions that fill in the missing pieces. -
Luminous
Luminous provides you a lot of information about the system and a lot of handy methods to quickly get useful data on the iOS platform. -
MisterFusion
MisterFusion is Swift DSL for AutoLayout. It is the extremely clear, but concise syntax, in addition, can be used in both Swift and Objective-C. Support Safe Area and Size Class. -
Cupcake
An easy way to create and layout UI components for iOS (Swift version). -
Anchors
Declarative, extensible, powerful Auto Layout for iOS 8+ and macOS 10.10+ -
QuickLayout
Written in pure Swift, QuickLayout offers a simple and easy way to manage Auto Layout in code. -
ManualLayout
✂ Easy to use and flexible library for manually laying out views and layers for iOS and tvOS. Supports AsyncDisplayKit. -
TapticEngine
TapticEngine generates haptic feedback vibrations on iOS device. -
WatchShaker
Simple motion detector for ⌚️ (watchOS) shake gesture. -
MondrianLayout
🏗 A way to build AutoLayout rapidly than using InterfaceBuilder(XIB, Storyboard) in iOS. -
BBLocationManager
A Location Manager for easily implementing location services & geofencing in iOS. Ready for iOS 11. -
Framezilla
Elegant library that wraps working with frames with a nice chaining syntax. -
Anchorman
An autolayout library for the damn fine citizens of San Diego. -
Auto Layout Magic
Build 1 scene, let AutoLayoutMagic generate the constraints for you! -
SuperLayout
SuperLayout is a Swift library that makes using Auto Layout a breeze.
Appwrite - The open-source backend cloud platform
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of TinyConstraints or a related project?
README
TinyConstraints is the syntactic sugar that makes Auto Layout sweeter for human use.
Features
- [X] Pure Swift 5 sweetness.
- [X] Everything you can do with Auto Layout, but shorter.
- [X] Constraints are active by default.
- [X] 100% compatible with other Auto Layout code.
- [X] Optionally store your constraints.
- [X] Set constraint priorities upon creation.
- [X] Constrain directly to the superview.
- [X] Stack views together with one line of code.
- [X] No need to set
translatesAutoresizingMaskIntoConstraints
becauseTinyConstraints
does it for you.
Examples
Edges
Attaching a view to its superview with NSLayoutConstraint
:
NSLayoutConstraint.activate([
view.topAnchor.constraint(equalTo: superview.topAnchor, constant: 0),
view.leadingAnchor.constraint(equalTo: superview.leadingAnchor, constant: 0),
view.bottomAnchor.constraint(equalTo: superview.bottomAnchor, constant: 0),
view.trailingAnchor.constraint(equalTo: superview.trailingAnchor, constant: 0)
])
with TinyConstraints
:
view.edgesToSuperview()
or:
view.edgesToSuperview(insets: .top(10) + .left(10))
Center
Constraining the center of a view to its superview with NSLayoutConstraint
:
NSLayoutConstraint.activate([
view.centerXAnchor.constraint(equalTo: superview.centerXAnchor, constant: 0)
view.centerYAnchor.constraint(equalTo: superview.centerYAnchor, constant: 0)
])
with TinyConstraints
:
view.center(in: superview)
or:
view.center(in: superview, offset: CGPoint(x: 10, y: 10))
Basic Use
Typealiases
TinyConstraints
gives you convenient and tiny typealiases for handling constraints.
Constraint
=NSLayoutConstraint
Constraints
=[NSLayoutConstraint]
Equal and Unequal Anchors
This constraints the top-anchor
of the view to the top-anchor
of the superview:
view.top(to: superview)
This constraints the top-anchor
of firstView
to the bottom-anchor
of secondView
:
firstView.topToBottom(of: secondView)
Constrain to Superview
Often you need to constrain a view to it's superview, with TinyConstraints you can do this super easy:
view.edgesToSuperview()
Or only one edge:
view.topToSuperview()
Or you can attach all edges except one, like this:
view.edgesToSuperview(excluding: .bottom)
Relation and Priority
For almost all constraints you can set the relation
and priority
properties. The default relation is .equal
and the default priority is .required
:
container.width(150, relation: .equalOrLess, priority: .high)
Storing Constraints
Here we create a set of inactive constraints and store these to our property:
let constraints = view.size(CGSize(width: 100, height: 100), isActive: false)
Activation and Deactivation
Besides the default NSLayoutConstraint
activation, TinyConstraints
also provides a way to activate a set of constraints:
constraints.activate()
You can also do this in an animation:
oldConstraints.deActivate()
constraints.activate()
UIViewPropertyAnimator(duration: 1, dampingRatio: 0.4) {
self.layoutIfNeeded()
}.startAnimation()
Animating Constraint Constants
Here we add a height constraint to a view, store it and animate it later:
let height = view.height(100)
height.constant = 200
UIViewPropertyAnimator(duration: 1, dampingRatio: 0.4) {
self.layoutIfNeeded()
}.startAnimation()
Stack
Stack provides a way of constraining views together in a superview:
let views = [logo, title, description]
superview.stack(views, axis: .vertical, spacing: 10)
Find these examples and more in the Example Project.
Installation
CocoaPods
TinyConstraints is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "TinyConstraints"
Carthage
TinyConstraints is available through Carthage. To install it, simply add the following line to your Cartfile:
github "roberthein/TinyConstraints"
Swift Package Manager
TinyConstraints is available through Swift Package Manager. To install
it, in Xcode 11.0 or later select File
> Swift Packages
> Add Package Dependency...
and add TinyConstraints repository URL:
https://github.com/roberthein/TinyConstraints.git
Tutorials
Here are some video tutorials made by Alex Nagy.
Suggestions or feedback?
Feel free to create a pull request, open an issue or find me on Twitter.