SwiftyLayout alternatives and similar libraries
Based on the "Layout" category.
Alternatively, view SwiftyLayout 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 -
PureLayout
The ultimate API for iOS & OS X Auto Layout — impressively simple, immensely powerful. Objective-C and Swift compatible. -
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 -
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. -
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. -
ManualLayout
✂ Easy to use and flexible library for manually laying out views and layers for iOS and tvOS. Supports AsyncDisplayKit. -
QuickLayout
Written in pure Swift, QuickLayout offers a simple and easy way to manage Auto Layout in code. -
MondrianLayout
🏗 A way to build AutoLayout rapidly than using InterfaceBuilder(XIB, Storyboard) in iOS. -
Framezilla
DISCONTINUED. Elegant library that wraps working with frames with a nice chaining syntax. -
BBLocationManager
A Location Manager for easily implementing location services & geofencing in iOS. Ready for iOS 11.
CodeRabbit: AI Code Reviews for Developers

* 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 SwiftyLayout or a related project?
README
SwiftyLayout
SwiftyLayout is a framework that allows to describe layout constraints (ie NSLayoutConstraint) as a simple mathematical formula in a Swift program.
About Version
- SwiftyLayout 3 for Swift 2
- SwiftyLayout 4 for Swift 3
Code Examples
Basic usage
Using the framework, a layout constraint that "the width of the view A is equal to minus 4.0 to 50% of the width of the Views B" follows:
viewA[.Width] == 0.5 * viewB[.Width] - 4.0
This is the same layout constraints with the following code:
NSLayoutConstraint(
item: viewA, attribute: .Width,
relatedBy: .Equal,
toItem: viewB, attribute: .Width,
multiplier: 0.5, constant: -4.0)
e.g. Aspect ratio
A layout constraint that "the aspect ratio of the view A is 3:4" follows:
viewA[.Width] * 3.0 == viewA[.Height] * 4.0
This is the same layout constraints with the following code:
NSLayoutConstraint(
item: viewA, attribute: .Width,
relatedBy: .Equal,
toItem: viewA, attribute: .Height,
multiplier: 4.0/3.0, constant: 0.0)
e.g. Specify the priority
The framework has priority specification operator ~
like the following.
innerView[.Leading] == outerView[.Leading] + 4.0 ~ 750.0
This is the same layout constraints with the following code:
var constraint = NSLayoutConstraint(
item: innerView, attribute: .Leading,
relatedBy: .Equal,
toItem: outerView, attribute: .Leading,
multiplier: 1.0, constant: 4.0)
constraint.priority = 750.0
// -> constraint
Please refer to the code for the sample application and test case, too.
Refrence Guide
ConstraintTerm
ConstraintTerm means a term that contains a view in the right side or the left side of a layout constraint.
For example, a ConstraintTerm representing the width .Width
of view viewA
:
viewA[.Width]
viewA
is a UIView instance object, .Width
is a NSLayoutAttribute
value.
ConstraintTerm is defined as a structure such as the following:
public struct ConstraintTerm
{
let view: UIView?
let attribute: NSLayoutAttribute
var multiplier: CGFloat = 1.0
var constant: CGFloat = 0.0
}
Operators
The following table, CONSTANT means CGFloat value
operator | lhs | rhs | value | semantics |
---|---|---|---|---|
+ | ConstraintTerm | CONSTANT | ConstraintTerm | add rhs value to lhs.constant |
+ | CONSTANT | ConstraintTerm | ConstraintTerm | add lhs value to rhs.constant |
- | ConstraintTerm | CONSTANT | ConstraintTerm | subtract rhs value from lhs.constant |
* | ConstraintTerm | CONSTANT | ConstraintTerm | multiply rhs value to lhs.multiplier and lhs.constant |
* | CONSTANT | ConstraintTerm | ConstraintTerm | multiply lhs value to rhs.multiplier and rhs.constant |
/ | ConstraintTerm | CONSTANT | ConstraintTerm | divide lhs.multiplier and lhs.constant by rhs value |
== | ConstraintTerm | ConstraintTerm | NSLayoutConstraint | create a layout constraint that "lhs is equal to lhs" |
== | ConstraintTerm | CONSTANT | NSLayoutConstraint | ditto |
== | CONSTANT | ConstraintTerm | NSLayoutConstraint | ditto |
<= | ConstraintTerm | ConstraintTerm | NSLayoutConstraint | create a layout constraint that "lhs is less than or equal to lhs" |
<= | ConstraintTerm | CONSTANT | NSLayoutConstraint | ditto |
<= | CONSTANT | ConstraintTerm | NSLayoutConstraint | ditto |
>= | ConstraintTerm | ConstraintTerm | NSLayoutConstraint | create a layout constraint that "lhs is greater than or equal to lhs" |
>= | ConstraintTerm | CONSTANT | NSLayoutConstraint | ditto |
>= | CONSTANT | ConstraintTerm | NSLayoutConstraint | ditto |
~ | NSLayoutConstraint | CONSTANT(Float) | NSLayoutConstraint | Change the priority of a layout constraint, and return the constraint |
Requirements
- Swift 2.0 (Xcode 7 or later)
- iOS
- iOS 8 or later / iOS 7 (by coping the source files directly)
- Mac
- Mac OS X 10.10 or later
Installation
There are two options.
Using Carthage
Using Carthage, it's easy to add SwiftyLayout to the project.
- Add
github "fhisa/SwiftyLayout"
to your Cartfile. - Run
carthage update
- Add SwiftyLayout.framework in Carthage/Build/iOS to your Xcode project.
Copying source files directly (iOS 7)
- Add this repository as a git submodule:
shell $ git submodule add https://github.com/fhisa/SwiftyLayout.git PATH_TO_SUBMODULE // or $ carthage update --use-submodules
- Then just add references of SwiftyLayout/*.swift to your Xcode project.
TODO
- CocoaPods support
license
SwiftyLayout is released under the MIT license.
*Note that all licence references and agreements mentioned in the SwiftyLayout README section above
are relevant to that project's source code only.