Swiftpack.co -  Hsieh-1989/HSLayout as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Hsieh-1989/HSLayout
Composable Auto Layout Constraints
.package(url: "https://github.com/Hsieh-1989/HSLayout.git", from: "0.1.0")

HSLayout

A library for building autolayout constraints in a consistent and understandable way, with composition in mind.

Requirements

  • iOS 11.0+ / Mac OS X 11.0+ / tvOS 11.0+
  • Xcode 12.0+
  • Swift 5.3+

Installation

You can add HSLayout to an Xcode project by adding it as a package dependency.

https://github.com/Hsieh-1989/HSLayout.git

If you want to use HSLayout in a SwiftPM project, it's as simple as adding a dependencies clause to your Package.swift:

dependencies: [
    .package(url: "https://github.com/Hsieh-1989/HSLayout.git", from: "0.1.0")
]

Examples

Edges

Attaching a view to its superview with NSLayoutConstraint:

view.translatesAutoresizingMaskIntoConstraints = false
superview.addSubview(view)
NSLayoutConstraint.activate([
    view.topAnchor.constraint(equalTo: superview.topAnchor, constant: 0),
    view.leadingAnchor.constraint(equalTo: superview.leadingAnchor, constant: 0),
    view.bottomAnchor.constraint(equalTo: superview.bottomAnchor, constant: 0),
    view.trailingAnchor.constraint(equalTo: superview.trailingAnchor, constant: 0)
])

with HSLayout:

superview.addSubview(view, layout: .fit())

Center

Constraining the center of a view to its superview with NSLayoutConstraint:

NSLayoutConstraint.activate([
    view.centerXAnchor.constraint(equalTo: superview.centerXAnchor, constant: 0)
    view.centerYAnchor.constraint(equalTo: superview.centerYAnchor, constant: 0)
])

with HSLayout:

view.constraints(to: superview, layout: .center)

GitHub

link
Stars: 1
Last commit: 4 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

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