Swiftpack.co - cp3hnu/Bricking as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
cp3hnu/Bricking
Autolayout for iOS and macOS
.package(url: "https://github.com/cp3hnu/Bricking.git", from: "4.1.3")

Bricking is Inspired by Stevia. The function is similar to Stevia. But supports the following features.

  • Supports iOS and macOS
  • Supports dynamical or conditional layout(issues#53)
  • Supports topLayoutGuide(iOS 9) , bottomLayoutGuide(iOS 9) and safeAreaLayoutGuide(iOS 11)
  • Support setting priority
  • Supports center-based layout
  • Supports view shrink(hide view and compress the space occupied by the view)
  • Supports NSLayoutAnchor equation (iOS 9+)
  • The architecture and code are more clear

Installation

Carthage

github "cp3hnu/Bricking"
  • Drag and drop Bricking.framework from /Carthage/Build/iOS/ to Linked Frameworks and Libraries in Xcode (Project>Target>General>Linked Frameworks and Libraries)
  • Add new run script
  /usr/local/bin/carthage copy-frameworks
  • Add Input files $(SRCROOT)/Carthage/Build/iOS/Bricking.framework

Swift Package

File -> Swift Packages -> Add Package Dependency, then search bricking.

Usage

Example

asv(
    portraitImgView,
    idLabel,
    dateLabel
)
        
layout(
    15,
    |-15-portraitImgView.size(30)-idLabel-15-|,
    10,
    |-15-dateLabel-15-|,
    15
)

Layout dynamically

let views = [Any](https://raw.github.com/cp3hnu/Bricking/master/)
if isTrue {
    views += [view1, view2]
} else {
    views += [view3, view4]
}
asv(views)
layoutDynamically(views)

topLayoutGuide, bottomLayoutGuide

view.layout(
    topLayoutGuide.bottomAnchor,
    10,
    |subview1| ~ 50,
    10,
    |subview2|,
    bottomLayoutGuide.topmAnchor
)

safeAreaLayoutGuide

view.layout(
    view.safeAreaLayoutGuide.topAnchor,
    10,
    |subview1| ~ 50,
    10,
    |subview2|,
    view.safeAreaLayoutGuide.bottomAnchor
)

Center-based layout

label1-(>=4)-Bricking.centerX-(>=4)-label2

layout(
    |-15-label1-15-|,
    10,
    Bricking.centerY,
    10,
    |-15-label2-15-|
)

Shrink

layout(
    64,
    |nameView|,
    |cityView|,
    20,
    |-15-button-15-| ~ 40
)
cityView.shrinkVertically = true

is equal to
cityView.isHidden = true
layout(
    64,
    |nameView|,
    20,
    |-15-button-15-| ~ 40
)

Equation

label.laTop == 100
label2.laLeft == label1.laLeft + 20
label1.laWidth <= 50 % label2.laWidth

Priority

label.laBottom == 15 !! UILayoutPriorityRequired - 1

Percentage

label.width(40%)

Fill, Center and Align

tableView.fillContainer()
button.centerInContainer()
alignLefts(label1, label2)

Array Chainning

[label1, label2].alignLefts().alignTops()

More other

...

Requirements

  • Swift 5.0+
  • Xcode 10.0+
  • iOS 9+
  • macOS 10.12+

License

Released under the MIT license. See LICENSE for details.

GitHub

link
Stars: 3
Last commit: 1 week 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