Tiny Swift DSL for Autolayout

Overview

SwiftAutoLayout

SwiftAutoLayout is a tiny DSL for Autolayout intended to provide a more declarative way to express layout constraints. Here's a quick example:

// this:
let constraint = view1.left == view2.right * 2.0 + 10.0 ~ 750
		
// is equivalent to:
let constraint = NSLayoutConstraint(item: view1, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: view2, attribute: NSLayoutAttribute.Right, multiplier: 2.0, constant: 10.0)
constraint.priority = 750

You may notice that this looks a lot like the linear equation that a constraint represents. From the Apple documentation:

The relationship involves a first attribute, a relationship type, and a modified second value formed by multiplying an attribute by a constant factor and then adding another constant factor to it. In other words, constraints look very much like linear equations of the following form:

attribute1 == multiplier × attribute2 + constant

SwiftAutoLayout allows you to more effectively communicate the intent of a constraint by making the syntax more similar to the equation that it represents.

Installing

Use Swift Package Manager or add SwiftAutoLayout.xcodeproj as a subproject and link against either SwiftAutoLayout-iOS.framework or SwiftAutoLayout-Mac.framework depending on the platform.

Attributes

Layout attributes are defined as properties added in extensions of UIView and UILayoutGuide on iOS and NSView and NSLayoutGuide on OS X. For example, UIView.width and UIView.height represent NSLayoutAttribute.Width and NSLayoutAttribute.Height, respectively.

Layout guides (conforming to UILayoutSupport) in UIViewController are also supported using the topLayoutGuideTop, topLayoutGuideBottom, bottomLayoutGuideTop, and bottomLayoutGuideBottom properties.

Relations

Relations are expressed using the overloaded operators == (NSLayoutRelation.Equal), >= (NSLayoutRelation.GreaterThanOrEqual), and <= (NSLayoutRelation.LessThanOrEqual).

Examples

Activating Single Constraint

(view1.left == view2.right * 2.0 + 10.0 ~ 750).active = true

Activating Multiple Constraints

NSLayoutConstraint.activateConstraints([
    view2.centerX == view2.superview!.centerX,
    view2.centerY == view2.superview!.centerY,
    view1.left == view2.right * 2.0 + 10.0 ~ 750,
    view1.top == view2.bottom + 5.0,
    view1.width >= 200,
    view1.height >= 400,
    view1.trailing == layoutGuide.trailing,
    view2.leading == layoutGuide.leading
])

Contact

License

SwiftAutoLayout is licensed under the MIT License.

Comments
  • Compiler Segfault

    Compiler Segfault

    I've been attempting to use this project by simply adding SwiftAutoLayout.swift to my project and accessing it directly. The compiler recognizes all the methods, but segfaults on the build. I've experienced this in both Xcode 6 Betas 2 and 3.

    To reproduce, I just created a single view application using the default template from Xcode 6 Beta 3, added the SwiftAutoLayout.swift, and added this to the single view controller:

    override func viewDidLoad() {
        super.viewDidLoad()
    
        let box = UIView()
        box.backgroundColor = UIColor.blueColor()
    
        view.addConstraint(box.al_centerX == view.al_centerX)
        view.addConstraint(box.al_centerY == view.al_centerY)
        view.addConstraint(box.al_width == view.al_width / 2)
        view.addConstraint(box.al_height == view.al_height / 2)
    }
    

    The compiler issue also occurs when using intermediate variables like in the readme, a la

    let constraint = box.al_centerX == view.al_centerX
    view.addConstraint(constraint)
    

    On builds, I get:

    CompileSwift normal i386 com.apple.xcode.tools.swift.compiler
        cd /Volumes/WorkHD/Users/iterrell/src/play/SwiftAutoLayoutTest
        export PATH="/Applications/Xcode6-Beta3.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode6-Beta3.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
        /Applications/Xcode6-Beta3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -target i386-apple-ios8.0 -module-name SwiftAutoLayoutTest -O0 -sdk /Applications/Xcode6-Beta3.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk -g -module-cache-path /Users/iterrell/Library/Developer/Xcode/DerivedData/ModuleCache -I /Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Products/Debug-iphonesimulator -F /Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Products/Debug-iphonesimulator -c -j4 /Volumes/WorkHD/Users/iterrell/src/play/SwiftAutoLayoutTest/SwiftAutoLayoutTest/ViewController.swift /Volumes/WorkHD/Users/iterrell/src/play/SwiftAutoLayoutTest/SwiftAutoLayoutTest/AppDelegate.swift /Volumes/WorkHD/Users/iterrell/src/play/SwiftAutoLayoutTest/SwiftAutoLayoutTest/SwiftAutoLayout.swift -output-file-map /Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/Objects-normal/i386/SwiftAutoLayoutTest-OutputFileMap.json -serialize-diagnostics -emit-dependencies -emit-module -emit-module-path /Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/Objects-normal/i386/SwiftAutoLayoutTest.swiftmodule -Xcc -I/Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/SwiftAutoLayoutTest-generated-files.hmap -Xcc -I/Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/SwiftAutoLayoutTest-own-target-headers.hmap -Xcc -I/Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/SwiftAutoLayoutTest-all-target-headers.hmap -Xcc -iquote -Xcc /Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/SwiftAutoLayoutTest-project-headers.hmap -Xcc -I/Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Products/Debug-iphonesimulator/include -Xcc -I/Applications/Xcode6-Beta3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/DerivedSources/i386 -Xcc -I/Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/DerivedSources -Xcc -DDEBUG=1 -emit-objc-header -emit-objc-header-path /Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/Objects-normal/i386/SwiftAutoLayoutTest-Swift.h
    
    0  swift                    0x000000010f253de8 llvm::sys::PrintStackTrace(__sFILE*) + 40
    1  swift                    0x000000010f2542d4 SignalHandler(int) + 452
    2  libsystem_platform.dylib 0x00007fff9853d5aa _sigtramp + 26
    3  libsystem_platform.dylib 0x00007fac00000003 _sigtramp + 1739336307
    4  swift                    0x000000010f552b29 swift::NominalTypeDecl::getMembers(bool) const + 41
    5  swift                    0x000000010e62e139 swift::irgen::ClassMetadataLayout<(anonymous namespace)::FindClassMethodIndex>::addClassMembers(swift::ClassDecl*) + 329
    6  swift                    0x000000010e627de2 swift::irgen::emitVirtualMethodValue(swift::irgen::IRGenFunction&, llvm::Value*, swift::SILType, swift::SILDeclRef, swift::CanTypeWrapper<swift::SILFunctionType>, swift::ResilienceExpansion) + 434
    7  swift                    0x000000010e69448d swift::SILVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::ValueBase*) + 46205
    8  swift                    0x000000010e688800 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8896
    9  swift                    0x000000010e609d18 swift::irgen::IRGenModule::emitGlobalTopLevel() + 200
    10 swift                    0x000000010e675575 performIRGeneration(swift::IRGenOptions&, swift::Module*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1829
    11 swift                    0x000000010e675f23 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, unsigned int) + 51
    12 swift                    0x000000010e5e7b8e frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 4958
    13 swift                    0x000000010e5e681d main + 1533
    14 libdyld.dylib            0x00007fff901695fd start + 1
    15 libdyld.dylib            0x0000000000000038 start + 1877568060
    Stack dump:
    0.  Program arguments: /Applications/Xcode6-Beta3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Volumes/WorkHD/Users/iterrell/src/play/SwiftAutoLayoutTest/SwiftAutoLayoutTest/ViewController.swift /Volumes/WorkHD/Users/iterrell/src/play/SwiftAutoLayoutTest/SwiftAutoLayoutTest/AppDelegate.swift /Volumes/WorkHD/Users/iterrell/src/play/SwiftAutoLayoutTest/SwiftAutoLayoutTest/SwiftAutoLayout.swift -enable-objc-attr-requires-objc-module -target i386-apple-ios8.0 -module-name SwiftAutoLayoutTest -sdk /Applications/Xcode6-Beta3.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk -I /Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Products/Debug-iphonesimulator -F /Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Products/Debug-iphonesimulator -g -module-cache-path /Users/iterrell/Library/Developer/Xcode/DerivedData/ModuleCache -Xcc -I/Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/SwiftAutoLayoutTest-generated-files.hmap -Xcc -I/Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/SwiftAutoLayoutTest-own-target-headers.hmap -Xcc -I/Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/SwiftAutoLayoutTest-all-target-headers.hmap -Xcc -iquote -Xcc /Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/SwiftAutoLayoutTest-project-headers.hmap -Xcc -I/Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Products/Debug-iphonesimulator/include -Xcc -I/Applications/Xcode6-Beta3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/DerivedSources/i386 -Xcc -I/Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/DerivedSources -Xcc -DDEBUG=1 -emit-module-doc-path /Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/Objects-normal/i386/ViewController~partial.swiftdoc -O0 -emit-module-path /Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/Objects-normal/i386/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/Objects-normal/i386/ViewController.dia -emit-dependencies-path /Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/Objects-normal/i386/ViewController.d -o /Users/iterrell/Library/Developer/Xcode/DerivedData/SwiftAutoLayoutTest-aqahricjhkyokhfrtdfvmjefkvgk/Build/Intermediates/SwiftAutoLayoutTest.build/Debug-iphonesimulator/SwiftAutoLayoutTest.build/Objects-normal/i386/ViewController.o 
    1.  While emitting IR SIL function @_TFC19SwiftAutoLayoutTest14ViewController11viewDidLoadfS0_FT_T_ for 'viewDidLoad' at /Volumes/WorkHD/Users/iterrell/src/play/SwiftAutoLayoutTest/SwiftAutoLayoutTest/ViewController.swift:13:14
    <unknown>:0: error: unable to execute command: Segmentation fault: 11
    <unknown>:0: error: swift frontend command failed due to signal (use -v to see invocation)
    Command /Applications/Xcode6-Beta3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 254
    
    opened by ianterrell 3
  • OSX Support

    OSX Support

    Resolves #5.

    In this branch, all mentions of UIView in the code are replaced with ALView. The latter, depending on the platform, is typealiased to either UIView or NSView. The APIs are so similar that no other changes to the code were really necessary.

    The new OSX targets just use the same Swift files as this iOS versions do, so the only things that had to be added were the Info.plists and the OSX app delegate / main.swft files.

    Enjoy :)

    opened by noahd 3
  • Support for Beta 4

    Support for Beta 4

    This PR makes SwiftAutoLayout compatible with Xcode 6 DP4 and Swift's new access control functionality.

    The major changes:

    • Everything is now public. Not sure if it should be (especially all the relate* methods), but it has to for the unit tests to work (excerpt from the newest release notes):

    A limitation of the access control system is that unit tests cannot interact with the classes and methods in an application unless they are marked public. This is because the unit test target is not part of the application module.

    • Apple seems to have finally fixed the computed property segfault bug, so ALLayoutItem is a struct again! Everything seemed to work for me so far.

    This also resolves #8 (for me, at least). The actual bug is still in the compiler, but the mere act of changing the type of ALLayoutItem from an @objc class to a struct makes all of the symptoms vanish. When you change the type back, the compiler will still crash, but as a structure everything works swimmingly!

    opened by noahd 2
  • Potential workaround for computed property issue

    Potential workaround for computed property issue

    Hi! I think I've found a potential (temporary) solution for the computed property segfault bug. In fact, I was working on my own unpublished Auto Layout library (whose code is pretty much identical to yours, except for naming) a week ago when I encountered it :)

    It turns out the compiler only crashes when you use a computed property that won't seamlessly bridge over to Objective-C, so Int and other primitive types are allowed, but non-@objc Swift objects/structs aren't. All you'd have to do, until Apple fixes the compiler, is replace struct ALOperand with @objc class ALOperand and computed properties should be usable again!

    I haven't tested this with your code or made a PR yet because you might want to stick with the 'method style', but it worked for me; if you'd rather use computed properties, this could be a useful workaround.

    opened by noahd 2
  • How to implement a list of UIViews

    How to implement a list of UIViews

    Hey there, I'm curious to know if SwiftAutoLayout will accomplish my needs. I'd like to have a list of stacked UIView's that fill the width of the screen, each having a dynamic height, and each being seperated by 10 points apart from each other. AKA, something like Facebook's News Feed. Thanks!

    opened by sean-hill 1
  • Update / Remake Constraints

    Update / Remake Constraints

    First off: awesome idea to use operator overloading for defining layout constraints. There's one catch though - other autolayout frameworks provide methods to update / remove / remake layout constraints. Like Masonry: https://github.com/Masonry/Masonry/blob/master/Masonry/View%2BMASAdditions.h#L68

    How could we represent this with overloaded operators? I guess removing constraints better would be an own method call. It could also be called before making new constraints to provide the same functionality as remake. That leaves update. Should update be the default behavior?

    opened by fabb 1
  • Big negative impact on compilation time

    Big negative impact on compilation time

    After running a profiling script to check the compilation times of the project (because it began to be really slow) I noticed that the methods where I set up the constraints with this library are the ones that take the longest to compile and it's making the project to take between 4 - 5 min to run. The project is really small so it shouldn't be the case.

    This is the method that takes the longest to compile. 56690.86ms

    fileprivate func setupConstraints() {
            playerComponentView.translatesAutoresizingMaskIntoConstraints = false
            headerComponentView.translatesAutoresizingMaskIntoConstraints = false
            tabsComponentView.translatesAutoresizingMaskIntoConstraints = false
            componentsScrollView.translatesAutoresizingMaskIntoConstraints = false
            topHeaderView.translatesAutoresizingMaskIntoConstraints = false
            closeButton.translatesAutoresizingMaskIntoConstraints = false
            chromecastButton.translatesAutoresizingMaskIntoConstraints = false
            topTitleLabel.translatesAutoresizingMaskIntoConstraints = false
    
            if UIDevice.current.userInterfaceIdiom == .pad {
                addConstraints([componentsScrollView.width == width * 0.7,
                                componentsScrollView.top == top,
                                componentsScrollView.bottom == bottom,
                                componentsScrollView.centerX == centerX])
            } else {
                addConstraints([componentsScrollView.leading == leading,
                                componentsScrollView.top == top,
                                componentsScrollView.bottom == bottom,
                                componentsScrollView.trailing == trailing])
            }
    
            let playerHeight = (((UIScreen.main.bounds.height * 0.7) * 9) / 16)
            addConstraints([playerComponentView.leading == componentsScrollView.leading,
                            playerComponentView.trailing == componentsScrollView.trailing,
                            playerComponentView.top == componentsScrollView.top,
                            playerComponentView.height == playerHeight,
                            playerComponentView.width == componentsScrollView.width])
    
            addConstraints([headerComponentView.top == playerComponentView.bottom,
                            headerComponentView.leading == componentsScrollView.leading,
                            headerComponentView.trailing == componentsScrollView.trailing,
                            headerComponentView.width == componentsScrollView.width])
    
            addConstraints([tabsComponentView.leading == componentsScrollView.leading,
                            tabsComponentView.trailing == componentsScrollView.trailing,
                            tabsComponentView.top == headerComponentView.bottom,
                            tabsComponentView.bottom == componentsScrollView.bottom,
                            tabsComponentView.width == componentsScrollView.width])
    
            topHeaderBottomConstraint = (topHeaderView.bottom == top)
    
            addConstraints([topHeaderBottomConstraint,
                            topHeaderView.leading == componentsScrollView.leading,
                            topHeaderView.trailing == componentsScrollView.trailing])
    
            let buttonsTopMargin = (UIApplication.shared.statusBarFrame.height + 8)
    
            addConstraints([closeButton.trailing == topHeaderView.trailing - 8,
                            closeButton.top == top + buttonsTopMargin,
                            closeButton.width == 48,
                            closeButton.height == 48])
    
            addConstraints([chromecastButton.trailing == closeButton.leading - 8,
                            chromecastButton.top == closeButton.top,
                            chromecastButton.width == 48,
                            chromecastButton.height == 48])
    
            addConstraints([topTitleLabel.leading == topHeaderView.leading + DetailsViewDesignGuidelines.contentMargin,
                            topTitleLabel.trailing == chromecastButton.leading - 8,
                            topTitleLabel.top == topHeaderView.top + (UIApplication.shared.statusBarFrame.height + 20),
                            topTitleLabel.bottom == topHeaderView.bottom - 16])
    }
    

    By changing the constraints configuration to use NSLayoutConstraint directly it goes down to 10.56ms As you can see is quite difference.

    Any ideas on what could be the problem or how to fix this? I would really like to continue using this library because it makes so much easier and faster the constraints setup, but the impact it has on the build time is just too big and it will only get worse as the project gets bigger.

    opened by APesate 4
  • Installation section organization

    Installation section organization

    Hey, your library is really interesting.

    The only problem I found was the README.md, which needs an organization in the Installation Section I created this iOS Open source Readme Template so you can take a look on how to make it better. If you want, I can help you to organize the lib.

    What are your thoughts? 😄

    opened by lfarah 0
  • constant on LHS is ignored

    constant on LHS is ignored

    let a = scrollView.right == view.right - 100
    let b = scrollView.right + 100 == view.right
    
    

    would appear to be equivalent, no compile or runtime error occurs, but in the second form, the constant is ignored:

    a: <NSLayoutConstraint:0x7fcd02dee830 ETVTileHostingScrollView:0x7fcd0221b000.right == UIView:0x7fcd0141d840.right - 100>
    b: <NSLayoutConstraint:0x7fcd02ce4be0 ETVTileHostingScrollView:0x7fcd0221b000.right == UIView:0x7fcd0141d840.right>
    
    opened by aufflick 0
  • UITextView error

    UITextView error

    After update the XCode to the latest version which is 7.3.1 (7D1014), the UITextView is broken because Apple introduce new properties on it.

    So if I do myTextView.top I get always error.

    opened by carmelogallo 4
Releases(1.0.0)
  • 1.0.0(Jan 9, 2016)

    This is a full rewrite of SwiftAutoLayout with the following major changes/additions:

    • Setting layout priorities is supported using the ~ operator
    • Support for UILayoutGuide and NSLayoutGuide
    • Support for constraining using UIViewController layout guides
    • Layout item types are now parametrized using a shadow type that determines whether the constraint is an X axis, Y axis, or dimension constraint for additional type safety
    • The al_ prefixes have been dropped from the layout item accessors (e.g. view.al_left is now view.left)
    • The method equivalents (e.g. greaterThanOrEqualTo() instead of >=) to the operator overloads have been removed since these are needlessly verbose and do not add much value over using the (NS|UI)LayoutAnchor API
    Source code(tar.gz)
    Source code(zip)
Owner
Indragie Karunaratne
Indragie Karunaratne
A Swift Autolayout DSL for iOS & OS X

SnapKit is a DSL to make Auto Layout easy on both iOS and OS X. ⚠️ To use with Swift 4.x please ensure you are using >= 4.0.0 ⚠️ ⚠️ To use with Swift

null 19.1k Jan 2, 2023
Powerful autolayout framework, that can manage UIView(NSView), CALayer and not rendered views. Not Apple Autolayout wrapper. Provides placeholders. Linux support.

CGLayout Powerful autolayout framework, that can manage UIView(NSView), CALayer and not rendered views. Has cross-hierarchy coordinate space. Implemen

Koryttsev Denis 45 Jun 28, 2022
AutoLayout Micro DSL SPM from Chris Eidhof's article

EasyAutoLayout Intro EasyAutoLayout is a small framework built using the ideas presented in the article called Autolayout Micro DSL by Chris Eidhof. I

Alexandre Garrefa 0 Nov 28, 2021
SwiftLayout - View hierarchy and autolayout DSL library

SwiftLayout view hierarchy and autolayout DSL library goal 뷰의 계층구조와 constraint 관

iOS Swifty Krew 104 Dec 28, 2022
A declarative Auto Layout DSL for Swift :iphone::triangular_ruler:

Cartography ?? ?? Using Cartography, you can set up your Auto Layout constraints in declarative code and without any stringly typing! In short, it all

Robb Böhnke 7.3k Jan 4, 2023
An Impressive Auto Layout DSL for iOS, tvOS & OSX. & It is written in pure swift.

KVConstraintKit KVConstraintKit is a DSL to make easy & impressive Auto Layout constraints on iOS, tvOS & OSX with Swift Installation Using CocoaPods

Keshav Vishwkarma 90 Sep 1, 2022
A compact but full-featured Auto Layout DSL for Swift

Mortar allows you to create Auto Layout constraints using concise, simple code statements. Use this: view1.m_right |=| view2.m_left - 12.0 Instead of:

Jason Fieldman 83 Jan 29, 2022
An awesome Swift CSS DSL library using result builders.

An awesome Swift CSS DSL library using result builders.

Binary Birds 57 Nov 21, 2022
A bit of steroids for AutoLayout, powered by Swift.

AutoLayoutPlus AutoLayoutPlus is a Swift library consisting in a set of extensions to help dealing with Auto Layout programatically. With AutoLayoutPl

Rui Costa 27 Jul 25, 2022
Yet Another Swift Auto Layout DSL

FormationLayout Documentation FormationLayout is the top level layout class for one root view. FormationLayout takes a UIView as its rootView. transla

Evan Liu 53 Mar 31, 2022
An extension that simplifies the work with Swift AutoLayout by writing cleaner, more natural and easy-reading code.

Installation For now you're able to clone repo in your project or download ZIP folder manually. git clone https://github.com/votehserxam/AutoLayout.gi

Max 3 Nov 8, 2022
Write concise Autolayout code

Winner of Hacking with Swift Recommended award You + Stevia = ?? ?? Write concise, readable layouts ?? Reduce your maintenance time ?? Compose your st

Fresh 3.3k Jan 6, 2023
📱AutoLayout can be set differently for each device

DeviceLayout DeviceLayout is a Swift framework that lets you set Auto Layout constraints's differently for each device Using only IBInspector of Xcode

Cruz 171 Oct 11, 2022
An easier and faster way to code Autolayout

EZAnchor 中文介绍 An easier way to code Autolayout Are you annoyed of coding .active = true while using Autolayout Anchors over and over again? Are you an

Alex.Liu 25 Feb 20, 2022
The fast path to autolayout views in code

NorthLayout The fast path to autolayout views in code Talks https://speakerdeck.com/banjun/auto-layout-with-an-extended-visual-format-language at AltC

banjun 36 Jul 15, 2022
🏗 MondrianLayout - describing structured layout for AutoLayout

?? A DSL based layout builder for AutoLayout

Muukii 155 Dec 10, 2022
This "Calculator" application is a simple one screen design of calculator screen i have made this single screen design application just to practice AutoLayout concepts.

Calculator Layout This "Calculator" application is a simple one screen design of calculator screen i have made this single screen design application j

Chetan Parate 1 Oct 29, 2021
Harness the power of AutoLayout NSLayoutConstraints with a simplified, chainable and expressive syntax. Supports iOS and OSX Auto Layout

Masonry Masonry is still actively maintained, we are committed to fixing bugs and merging good quality PRs from the wider community. However if you're

null 18k Jan 5, 2023
An autolayout library for the damn fine citizens of San Diego.

Anchorman Do you think autolayout has to be hard? Nah. NSLayoutAnchor is pretty neat! But it's still a bit tedious of an API. Try writing .translatesA

Joe Fabisevich 79 May 25, 2022