Latest 0.2.0
License MIT
Platforms ios 8.0


Swifty approach to defining frame layouts.


Framing supports CocoaPods:

pod 'Framing'

What is Framing?

Framing is a tiny framework for defining view frames in more Swifty way. Think of it as a simple wrapper over CGRect that can save you time spend on math calculations when positioning view frames. Look:

let background = Frame(width: 300, height: 300)

let bottomLine1 = Frame(width: 300, height: 20)
    .putInside(background, alignTo: .bottomCenter)

let bottomLine2 = Frame(width: 300, height: 30)

let F1 = Frame(width: 50, height: 180)
    .putInside(background, alignTo: .middleLeft)
    .offsetBy(x: 90, y: -10)

let F2 = Frame(width: 70, height: 50)
    .putOnRight(of: F1, alignTo: .top)

let F3 = F2.offsetBy(y: 70)

Every Frame provides .rect property that returns CGRect for UIView.
e.g. greenView.frame = bottomLine2.rect


What Framing is not?

It’s not an animal :pig: or UI / Layout framework. It doesn’t import UIKit anywhere.

What you can do with Framing?

This will return frame moved by 10pt in both directions:

frame.offsetBy(x: 10, y: 10)

This will return frame that is 5pt smaller in each direction:

frame.inset(top: 5, left: 5, bottom: 5, right: 5)

This will return frame that is put above/below base frame:

frame.putAbove(base, alignTo: .left)
frame.putAbove(base, alignTo: .right)
frame.putAbove(base, alignTo: .center)
frame.putBelow(..., alignTo: ...) // ...

The same for left/right positioning:

frame.putOnLeft(of: base, alignTo: .top)
frame.putOnLeft(of: base, alignTo: .bottom)
frame.putOnLeft(of: base, alignTo: .middle)
frame.putOnRight(of: ..., alignTo: ...) // ...

This will return frame that is put inside base frame:

frame.putInside(base, alignTo: .topLeft)
frame.putInside(base, alignTo: .topCenter)
frame.putInside(base, alignTo: .middleCenter) // centers `frame` inside `base`

This will divide frame into 5 columns and return 2nd column frame:

frame.divideIntoEqual(columns: 5, take: 1)

The same for rows:

frame.divideIntoEqual(rows: 5, take: 1)

It’s possible to apply transforms conditionally using only Framing api:

let shouldBeOffsetted: Bool = ...
frame.if(condition: shouldBeOffsetted,
         then: { $0.offsetBy(x: 10).inset(top: 5) },
         else: { $0.inset(top: 5) })

// Or simpler:
frame.inset(top: 5)
     .if(shouldBeOffsetted) { $0.offsetBy(x: 10) }

Missing some API? Open a Pull Request or fill in the Issue.

Framing is still in development

This library is still in development, so incompatible API changes are possible until it reaches 1.0.0.


Framing is released under the MIT license. See the LICENSE file for more details.

Latest podspec

    "name": "Framing",
    "version": "0.2.0",
    "summary": "Swifty approach to defining frame layouts",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": "Maciek Grzybowski",
    "social_media_url": "",
    "platforms": {
        "ios": "8.0"
    "source": {
        "git": "",
        "tag": "0.2.0"
    "source_files": "Framing/*.swift",
    "pushed_with_swift_version": "3.0"

Pin It on Pinterest

Share This