Swiftpack.co - pmodernme/Composed as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by pmodernme.
pmodernme/Composed 0.1.0
CGGeometry extensions to make manual layout cleaner and easier to read.
⭐️ 1
🕓 30 weeks ago
.package(url: "https://github.com/pmodernme/Composed.git", from: "0.1.0")


Make designing views in layoutSubviews() simpler with extensions to CoreGraphics structs such as CGRect, CGSize, and CGPoint.

Composed is in its early stages of development. Thanks for your interest!


  • ☑ Create CGRect from CGSize by pinning to a CGPoint
  • ☑ Supports pinning by origin, center, and any corner
  • ☑ Easily access CGRect corners by value instead of deriving them
  • ☑ Adds convenience functions and variables such as center to CGRect and offset(by:) to CGPoint


The core concept of layout using Composed is making manual layout easier to read.

// Composed
boxView.frame = CGSize(width: 200, height: 125)
// CoreGraphics
let boxSize = CGSize(width: 200, height: 125)
boxView.frame = CGRect(
    x: bounds.midX - boxSize.width/2,
    y: bounds.midY - boxSize.height/2,
    width: boxSize.width,
    height: boxSize.height

You can chain functions referencing another CGRect's geometry.

// Composed
topLabel.frame = topLabel
    .sizeThatFits(width: boxView.frame.width)
                .offsetBy(dx: 0, dy: -4)

let insetBox = boxView.frame.insetBy(dx: 6, dy: 4)
bottomLabel.frame = bottomLabel

// CoreGraphics
let topLabelSize = topLabel.sizeThatFits(
        width: boxSize.width,
        height: .greatestFiniteMagnitude
topLabel.frame = CGRect(
    x: boxView.frame.minX,
    y: boxView.frame.minY - (topLabelSize.height + 4),
    width: topLabelSize.width,
    height: topLabelSize.height

let insetBox = boxView.frame.insetBy(dx: 6, dy: 4)
let bottomLabelSize = bottomLabel.sizeThatFits(insetBox.size)
bottomLabel.frame = CGRect(
    x: insetBox.maxX - bottomLabelSize.width,
    y: insetBox.maxY - bottomLabelSize.height,
    width: bottomLabelSize.width,
    height: bottomLabelSize.height


Zoe Van Brunt, zvb.io


Stars: 1
Last commit: 12 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

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