Swifty DSL for programmatic Auto Layout in iOS

Overview

WWLayout

WWLayout

Easy to write auto layout constraints, with minimal extensions to standard namespaces.

Feature Highlights

  • Easy to use, readable API
  • Backwards-compatible (i.e. pre iOS 11) Safe Area constraints
  • Tag constraints to easily switch between different layouts (coming soon)
  • Automatic switching of size-class based constraints (coming soon)

Introduction

Constraints are added to a view using the view's layout property, like so:

    myView.layout.width(400)

Multiple constraints are easily added by chaining calls:

    myView.layout.width(400).height(200)

A more complicated example:

    let container = UIView()
    let child = UIView()

    container.layout.fill(.safeArea)

    child.layout
      .fill(container, axis: .x, inset: 20)
      .center(in: container, axis: .y, priority: .high)
      .top(.lessOrEqual, to: container, offset: 100)
      .height(toWidth: 0.5)

Dcumentation

Documentation can be found here

Installation

Swift Package Manager

The WWLayout Package URL is:

https://github.com/ww-tech/wwlayout.git

Add the package dependency to your Xcode project using the File -> Swift Packages -> Add Package Dependency... menu item.

Cocoapods

Simply add WWLayout to your Podfile:

  pod 'WWLayout'

Contributing

Authors

License

WWLayout is © copyright by WW International.

WWLayout is licensed under the Apache-2.0 Open Source license.

Comments
  • [FEATURE] Add version of `fill` that accepts UIEdgeInsets

    [FEATURE] Add version of `fill` that accepts UIEdgeInsets

    The fill functions accept CGFloat or Insets values, and another version should be added that accepts a UIEdgeInsets - especially since it is directly convertible to Insets.

    good first issue 
    opened by g-mark 2
  • [FEATURE] Add version of `.size()` that accepts a CGSize

    [FEATURE] Add version of `.size()` that accepts a CGSize

    Problem When I have a CGSize, I have to access the width & height to pass into the size() method:

    func setupConstraints(with size: CGSize) {
      label.layout.size(size.width, size.height)
    }
    

    Solution I would like to just pass a CGSize to the size() method, like:

    func setupConstraints(with size: CGSize) {
      label.layout.size(size)
    }
    
    good first issue 
    opened by g-mark 1
  • Fix LayoutView creation

    Fix LayoutView creation

    We bumped into a weird (hopefully) edge case where we were adding a UIView directly to a UIWindow, and then using the automatic size class activation on some subviews within that UIView.

    A problem came up where the LayoutView instance used to listen for traitCollectionDidChange notifications was being created as a direct child of the UIWindow. WWLayout relies on the LayoutView instance to be released as the primary containing view is released. This naturally fits with using UIViewControllers - but breaks when adding directly to a UIWindow.

    The fix is to prevent LayoutView instances from being added directly to a UIWindow. I also wrapped all references to the auto-switching constrains held by the LayoutView in a WeakBox, as a defensive measure against any other oddball situations that might also cause problems.

    opened by g-mark 0
  • Bring project files up to date

    Bring project files up to date

    • Update SwiftLint config
    • Fix annoying "comment spacing" SwiftLint warnings
    • Update xcodeproj "last check version"
    • Add new file tempkate to the appleTV example
    opened by g-mark 0
  • Add versions of `fill` where the `inset` param is `UIEdgeInsets`

    Add versions of `fill` where the `inset` param is `UIEdgeInsets`

    Addresses: #28

    This PR adds versions of all the fill functions, that uses UIEdgeInsets for the inset parameter value type. This will allow for using a variable for the insets, like this:

    let insets = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
    view.layout.fill(.superview, inset: insets)
    
    opened by Osein 0
  • Tweaks for iOS 14 & Xcode 12

    Tweaks for iOS 14 & Xcode 12

    Updating the project files & adding a CircleCI job for Swift 5.3.

    Removed slather from the Gemfile since it isn't used, and including it is currently causing build errors in Circle (The Xcode 12 beta image doesn't have the dev tools installed yet - using Ruby 2.7 might fix it). Since we aren't reporting (or checking) code coverage yet in CircleCI this should be ok for now.

    opened by g-mark 0
  • Bump nokogiri from 1.10.4 to 1.10.8

    Bump nokogiri from 1.10.4 to 1.10.8

    Bumps nokogiri from 1.10.4 to 1.10.8.

    Release notes

    Sourced from nokogiri's releases.

    1.10.8 / 2020-02-10

    Security

    [MRI] Pulled in upstream patch from libxml that addresses CVE-2020-7595. Full details are available in #1992. Note that this patch is not yet (as of 2020-02-10) in an upstream release of libxml.

    1.10.7 / 2019-12-03

    Bug

    • [MRI] Ensure the patch applied in v1.10.6 works with GNU patch. #1954

    1.10.6 / 2019-12-03

    Bug

    • [MRI] Fix FreeBSD installation of vendored libxml2. [#1941, #1953] (Thanks, @​nurse!)

    1.10.5 / 2019-10-31

    Dependencies

    • [MRI] vendored libxml2 is updated from 2.9.9 to 2.9.10
    • [MRI] vendored libxslt is updated from 1.1.33 to 1.1.34
    Changelog

    Sourced from nokogiri's changelog.

    1.10.8 / 2020-02-10

    Security

    [MRI] Pulled in upstream patch from libxml that addresses CVE-2020-7595. Full details are available in #1992. Note that this patch is not yet (as of 2020-02-10) in an upstream release of libxml.

    1.10.7 / 2019-12-03

    Fixed

    • [MRI] Ensure the patch applied in v1.10.6 works with GNU patch. [#1954]

    1.10.6 / 2019-12-03

    Fixed

    1.10.5 / 2019-10-31

    Security

    [MRI] Vendored libxslt upgraded to v1.1.34 which addresses three CVEs for libxslt:

    • CVE-2019-13117
    • CVE-2019-13118
    • CVE-2019-18197
    • CVE-2019-19956

    More details are available at #1943.

    Dependencies

    • [MRI] vendored libxml2 is updated from 2.9.9 to 2.9.10
    • [MRI] vendored libxslt is updated from 1.1.33 to 1.1.34
    Commits
    • 6ce10d1 version bump to v1.10.8
    • 2320f5b update CHANGELOG for v1.10.8
    • 4a77fdb remove patches from the hoe Manifest
    • 570b6cb update to use rake-compiler ~1.1.0
    • 2cdb68e backport libxml2 patch for CVE-2020-7595
    • e6b3229 version bump to v1.10.7
    • 4f9d443 update CHANGELOG
    • 80e67ef Fix the patch from #1953 to work with both git and patch
    • 7cf1b85 Fix typo in generated metadata
    • d76180d add gem metadata
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Add support for Swift Package Manager

    Add support for Swift Package Manager

    Add support for SwiftPM. Included CircleCI job is build only - unit tests are run for all the other jobs.

    Added a sample project that targets Apple TV - this one uses SwiftPM. The existing sample app still uses the embedded WWLayout sub-project for easier development.

    Note: will need to change example app's reference to the package once merged into develop (currently points to the feature/swiftpm feature branch).

    opened by g-mark 0
  • Release 0.6.0

    Release 0.6.0

    Release 0.6.0

    • Added support for tagging constraints, https://github.com/ww-tech/wwlayout/issues/2
    • Added support for size classes, https://github.com/ww-tech/wwlayout/issues/6
    opened by g-mark 0
  • Release 0.5.7

    Release 0.5.7

    Release version 0.5.7.

    • add version of fill functions that accept a CGFloat (@g-mark)
    • add version of size function that accepts a CGSize (@gradyjenkins)
    opened by g-mark 0
  • Add versions of `fill` where the `inset` param is `CGFloat`

    Add versions of `fill` where the `inset` param is `CGFloat`

    Addresses: https://github.com/ww-tech/wwlayout/issues/1

    This PR adds versions of all the fill functions, that uses CGFloat for the inset parameter value type. This will allow for using a variable for the insets, like this:

    let padding: CGFloat = 4
    view.layout.fill(.superview, inset: padding)
    

    in addition to int/float literals like this:

    view.layout.fill(.superview, inset: 42)
    
    opened by g-mark 0
  • [FEATURE] Add code coverage to CircleCI

    [FEATURE] Add code coverage to CircleCI

    There is currently no code coverage reporting in CircleCI, and needs to be added - preferably with a coverage threshold.

    Additionally, a code coverage badge needs to be added to the main Read Me file.

    opened by g-mark 0
  • [FEATURE] Add SwiftLint to CircleCI

    [FEATURE] Add SwiftLint to CircleCI

    SwithLint is currently only run locally in Xcode, and only if a user has it installed - not to mention having the latest version.

    SwiftLint should be run as a part of every build-test workflow in CircleCI, and further configured to prevent merging PRs that introduce any new warnings.

    opened by g-mark 0
  • [FEATURE] Add support for UILayoutGuide

    [FEATURE] Add support for UILayoutGuide

    Is your feature request related to a problem? Please describe. Add WWLayout support for UILayoutGuide.

    Describe the solution you'd like Being able to use WWLayout to add constraints to UILayoutGuide just like UIView.

    opened by gradyjenkins 0
  • [FEATURE] Arrange and Align helper methods

    [FEATURE] Arrange and Align helper methods

    Seems that a common task is for a bunch of child views to horizontally fill their parent, with possibly different insets. It would be interesting to explore this kind of convenience:

    .arrangeViews(.fillX, view1 - 40, view2 - 40, view3 - 15, view4 - 32)
    
    • options could be: centerX, fillX, leftAlign, rightAlign, plus same for vertical
    • maybe have a param for an at: offset, like (.leftAlign, at: leftEdge + 20, ...)

    Or, something like:

       align(.top/.left/.right/.bottom, views: Anchorable...)
       
       distribute(.horizontally/.vertically, views: Anchorable...)
    
    opened by g-mark 0
Releases(0.8.0)
Owner
WW Tech
WW inspires healthy habits for real life, using cutting edge science and technology to meet our community where they are and own scalable behavior change.
WW Tech
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 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
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
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
A powerful Swift programmatic UI layout framework.

Build dynamic and beautiful user interfaces like a boss, with Swift. Neon is built around how user interfaces are naturally and intuitively designed.

Mike 4.6k Dec 26, 2022
Programmatic view layout for the rest of us.

Façade Important Facade is no longer under active development, and as such if you create any issues or submit pull requests, it's not very likely to b

Mike 696 Aug 3, 2022
Auto Layout (and manual layout) in one line.

Auto Layout (and manual layout) in one line. Quick Look view.bb.centerX().below(view2).size(100) It’s equivalent to iOS 9 API: view.centerXAnchor.cons

Javier Zhang 74 Oct 19, 2022
Auto Layout made easy with the Custom Layout.

Auto Layout made easy with the Custom Layout. Getting started CocoaPods CocoaPods is a dependency manager for Cocoa projects. You can install it with

Malith Nadeeshan 1 Jan 16, 2022
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]

Extremely Fast views layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainabl

layoutBox 2.1k Dec 22, 2022
The ultimate API for iOS & OS X Auto Layout — impressively simple, immensely powerful. Objective-C and Swift compatible.

The ultimate API for iOS & OS X Auto Layout — impressively simple, immensely powerful. PureLayout extends UIView/NSView, NSArray, and NSLayoutConstrai

PureLayout 7.6k Jan 6, 2023
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
Random-Colors-iOS - Random colors generator app with auto layout

Random Colors Random colors generator app with auto layout Demo demo.mp4 Depende

Adem Özcan 8 Mar 23, 2022
Auto Layout made easy

EasyPeasy is a Swift framework that lets you create Auto Layout constraints programmatically without headaches and never ending boilerplate code. Besi

Carlos Vidal 1.9k Dec 23, 2022
Lightweight Swift framework for Apple's Auto-Layout

I am glad to share with you a lightweight Swift framework for Apple's Auto-Layout. It helps you write readable and compact UI code using simple API. A

null 349 Dec 20, 2022
Auto Layout In Swift Made Easy

Swiftstraints Swiftstraints can turn verbose auto-layout code: let constraint = NSLayoutConstraint(item: blueView, attr

null 119 Jan 29, 2022
TinyConstraints is the syntactic sugar that makes Auto Layout sweeter for human use.

TinyConstraints is the syntactic sugar that makes Auto Layout sweeter for human use. Features Pure Swift 5 sweetness. Everything you can do with Auto

Robert-Hein Hooijmans 3.8k Jan 5, 2023
Intuitive and powerful Auto Layout library

Align introduces a better alternative to Auto Layout anchors. Semantic. Align APIs focus on your goals, not the math behind Auto Layout constraints. P

Alexander Grebenyuk 338 Oct 18, 2022
⚓️ Declarative, extensible, powerful Auto Layout

EasyAnchor ❤️ Support my apps ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut m

Khoa 449 Nov 10, 2022
Template auto layout cell for automatically UITableViewCell height calculating

UITableView-FDTemplateLayoutCell Overview Template auto layout cell for automatically UITableViewCell height calculating. Basic usage If you have a se

null 10k Dec 31, 2022