Swiftpack.co - gbrlCM/LambdaLayoutKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by gbrlCM.
gbrlCM/LambdaLayoutKit 1.1.2
Library for helping with AutoLayout code, making it more concise and simple.
⭐️ 2
🕓 3 years ago
iOS
.package(url: "https://github.com/gbrlCM/LambdaLayoutKit.git", from: "1.1.2")

Logo

Platform SPM

Lambda Layout Kit (LK) is a library for dealing with auto layout in a simpler and modern way, using it you can configure your views layouts inside of closures or using shortcut methods, making your layout code cleaner and more readable.

Requirements

  • Swift 5.0 or later
  • iOS 13 or later
  • XCode 11 or later

Instalation

LK uses Swift Package Manager as its distribution method, to use it you can fetch LK via XCode or adding it to your package.swift depencies list.

Via XCode

  1. In a Xcode project, click on "File"
  2. Click on "Swift Packages" and select "Add Package Dependency"
  3. Paste the web url for this repository: https://github.com/gbrlCM/LambdaLayoutKit.git
  4. Set Rules to Branch on "main"

After this, you can fetch the latest changes to the framework by selecting "Update to Latest Package Versions" in step 2.

Via Package.swift

If you don't already have a Package.swift file, create one and add the following .package URL.

import PackageDescription

let package = Package(
    ...
    dependencies: [
        .package(url: "https://github.com/gbrlCM/LambdaLayoutKit.git", "1.1.2")
    ],
    ...
)

Usage

There is two ways to use LK the first is with the layout method inside any UIView, with that you can configure any view constraints inside the configuration closure. The other way is with the shortcut methods for common constraint combinations like stretch the view to another view bounds or center one view inside another.

Layout method:


import UIKit
import LambdaLayoutKit

class SomeViewController: UIViewController {

    ...
    @LKView childView: UIView
    ...

    overide func viewDidLoad() {
        ...
        
        childView.layout { anchors in
            anchors
                .top(attachTo: view.topAnchor)
                .leading(attachTo: view.leadingAnchor)
                .trailing(attachTo: view.trailingAnchor)
                .bottom(attachTo: view.bottomAnchor)
        }
        ...
    }
}

Shortcuts:

Inside LK there is a few shortcut methods for common constraints, some are only available for views with intrinsic size other are available for all kinds of views you can see the relation in the examples bellow.

Pin shortcuts

Pin Shortcuts

Stretch shortcuts

Using layout guides

    childView.stretchToBounds(of: parentView.layoutMarginGuide)

Using Views

    childView.stretchToBounds(of: parentView)

Goals

I made this library for learning Auto Layout and how to build libraries. I hope it helps you to write cleaner and clearer layout code.

Next steps

  • Make tests
  • Make a proper doc using Jazzy
  • Study the necessity of more shortcuts

GitHub

link
Stars: 2
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

v.1.1.2
3 years ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics