Skip to content

A collection of additional layout anchor types meant to complement UIKit's existing constraint system.

License

Notifications You must be signed in to change notification settings

berbschloe/Squidward

Repository files navigation

Squidward

A collection of additional layout anchor types meant to complement UIKit's existing constraint system.

Swift CocoaPods SPM supported Platform

Requirements

  • iOS 13
  • Xcode 13
  • Swift 5.5

Instalation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate the library into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'Squidward', '1.4.2'

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

dependencies: [
    .package(url: "https://github.com/berbschloe/Squidward.git", from: "1.4.2")
]

Usage

Importing

It would be recommended to add the library globally because it can get annoying importing it everywhere.

// Add this to a GlobalImports.swift
@_exported import Squidward

Constraints

Old Way

let childView = UIView()

override func viewDidLoad() {
    super.viewDidLoad()

    NSLayoutConstraint.activate([
        childView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 10),
        childView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: 10),
        childView.topAnchor.constraint(equalTo: view.topAnchor, constant: -10),
        childView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -10),
    ])
}

Squidward Way

let childView = UIView()

override func viewDidLoad() {
    super.viewDidLoad()

    NSLayoutConstraint.activate {
        childView.edgeAnchors.constraint(equalTo: view.edgeAnchors, constant: 10)
    }
}

Variants

childView.edgeAnchors.constraint(equalTo: view.edgeAnchors) // default zero constant

childView.edgeAnchors.constraint(edges: [.left, .right, .top], equalTo: view.edgeAnchors) // constrain specific edges

childView.edgeAnchors.constraint(
    equalTo: view.edgeAnchors, 
    constant: UIEdgeInsets(top: 10, left: 20, bottom: 30, right: 40) // custom insets with no need to apply a negative
)

About

A collection of additional layout anchor types meant to complement UIKit's existing constraint system.

Resources

License

Stars

Watchers

Forks

Packages

No packages published