All Projects → square → Paralayout

square / Paralayout

Licence: apache-2.0
Paralayout is a set of simple, useful, and straightforward utilities that enable pixel-perfect layout in iOS. Your designers will love you.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Paralayout

Interfacss
The CSS-inspired styling and layout framework for iOS
Stars: ✭ 92 (-87.6%)
Mutual labels:  uikit, layout, flexbox
TableViewKit
Empowering UITableView with painless multi-type cell support and built-in automatic state transition animations
Stars: ✭ 105 (-85.85%)
Mutual labels:  layout, uikit
StackViewLayout
Coming soon!
Stars: ✭ 26 (-96.5%)
Mutual labels:  layout, flexbox
flexbin
Pure CSS, flexible and gapless image gallery layout like Google Images and 500px.com
Stars: ✭ 93 (-87.47%)
Mutual labels:  layout, flexbox
how-to-css
howtocss.dev
Stars: ✭ 48 (-93.53%)
Mutual labels:  layout, flexbox
nice-react-layout
Create complex and nice Flexbox-based layouts, without even knowing what flexbox means
Stars: ✭ 70 (-90.57%)
Mutual labels:  layout, flexbox
gymnast
🤸 Configurable grid and layout engine for React
Stars: ✭ 35 (-95.28%)
Mutual labels:  layout, flexbox
Uicollectionviewsplitlayout
UICollectionViewSplitLayout makes collection view more responsive.
Stars: ✭ 226 (-69.54%)
Mutual labels:  uikit, layout
React Flexview
A powerful React component to abstract over flexbox and create any layout on any browser
Stars: ✭ 276 (-62.8%)
Mutual labels:  layout, flexbox
Flexbox React
Unopinionated, standard compliant flexbox component. No propietary APIs. Nothing but flexbox.
Stars: ✭ 319 (-57.01%)
Mutual labels:  layout, flexbox
React Native Responsive Grid
Bringing the Web's Responsive Design to React Native
Stars: ✭ 369 (-50.27%)
Mutual labels:  layout, flexbox
examples
speedata Publisher examples
Stars: ✭ 25 (-96.63%)
Mutual labels:  layout, typesetting
flexboxes
CSS flexbox framework with pure flexbox grid ability
Stars: ✭ 27 (-96.36%)
Mutual labels:  layout, flexbox
griding
🧱 lean grid & responsive for react
Stars: ✭ 18 (-97.57%)
Mutual labels:  layout, flexbox
Leerraum.js
A PDF typesetting library with exact positioning and hyphenated line breaking
Stars: ✭ 233 (-68.6%)
Mutual labels:  typesetting, layout
react-flex-columns
Easy layout columns for React - Using Flexbox under the hood.
Stars: ✭ 18 (-97.57%)
Mutual labels:  layout, flexbox
Collectionviewpaginglayout
a simple but highly customizable paging layout for UICollectionView.
Stars: ✭ 947 (+27.63%)
Mutual labels:  uikit, layout
Flex Layout
Provides HTML UI layout for Angular applications; using Flexbox and a Responsive API
Stars: ✭ 5,705 (+668.87%)
Mutual labels:  layout, flexbox
Layout Demo
Various Layouts Of CSS
Stars: ✭ 264 (-64.42%)
Mutual labels:  layout, flexbox
Uicollectionview Layouts Kit
📐 A set of custom layouts for UICollectionView with examples [Swift 5.3, iOS 12].
Stars: ✭ 410 (-44.74%)
Mutual labels:  uikit, layout

Paralayout

CI Status Carthage Compatibility Version License Platform

Paralayout is a set of simple, useful, and straightforward utilities that enable pixel-perfect layout in iOS. Your designers will love you.

Getting Started

CocoaPods

Integrating Paralayout into your iOS project via CocoaPods is simple:

platform :ios, '9.0'
pod 'Paralayout'

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Paralayout into your Xcode project using Carthage, specify it in your Cartfile:

github "Square/Paralayout"

Run carthage to build the framework and drag the built Paralayout.framework into your Xcode project.

Submodules

Or, manually check out the submodule with git submodule add [email protected]:Square/Paralayout.git, drag Paralayout.xcodeproj to your workspace, and add Paralayout as a build dependency.


Usage

Paralayout is a set of à la carte utilities, of which you can use as much or as little functionality as you like.

UILabel Subclass: Label

The Label class makes text look its best, and takes less cumbersome code to configure:

  • Style text without directly interacting with NSAttributedString or NSParagraphStyle (any more than you want to)
  • Get "compact" line wrapping that makes it unnecessary to introduce artificial line breaks into your copy
  • Hyperlinks are tappable (no need to use a UITextView)

UIView Subclass: Hairline

A Hairline will size itself correctly on any screen resolution, and provides conveniences for positioning within its superview.

/// Put a line at the bottom of the view, inset 20 points on each side.
let separator = Hairline.new(in: view, at: .maxYEdge, inset: 20)

New Value Type: Interpolation

Get the math right for multi-phase layout transitions and animations without tearing your hair out! Under the hood it’s simply a value between 0 and 1, but it makes computing that value, and deriving a new value from it, effortless.

// Determine how far we are into the transition of collapsing the header.
let headerCollapseAmount = Interpolation(of: header.frame.height, from: maxHeaderHeight, to: minHeaderHeight)

// The icon shrinks to half its usual size...
let avatarSize = headerCollapseAmount.interpolate(from: 80, to: 40)
avatar.frame.size = CGSize(width: avatarSize, height: avatarSize)

// ...as it completely fades out.
avatar.alpha = headerCollapseAmount.interpolate(from: 1, to: 0)

New Value Type: AspectRatio

Create an aspect ratio from any size, rect, or width/height value, and use it to compute pixel-snapped frame rectangles.

videoPlayer.frame = AspectRatio.widescreen.rect(toFit: bounds, at: .topCenter, in: view)

CGGeometry Extensions

These extensions provide numerous conveniences for computing rectangles and snapping coordinates to pixel dimensions. The ScaleFactorProviding protocol encapsulates the latter, allowing a view to provide the context necessary to align its subviews to pixels. One benefit of this approach is that unit tests can cover both 2x and 3x scale factors regardless of the simulator used to run the test.

UIFont Extensions

The extra space within a label above the "cap height" and below the "baseline" of its font is deterministic but non-obvious, especially at different scale factors. The simple LabelCapInsets value type encapsulates that logic.

UIView Alignment Extensions

The core positioning function (and its numerous derived convenience functions) allows one view to be positioned relative to another view:

titleLabel.align(.leftCenter, with: icon, .rightCenter, horizontalOffset: 8)
icon.alignToSuperview(.topCenter, inset: 20)

UIView Sizing Extensions

These methods extend UIView.sizeThatFits(:) and UIView.sizeToFit() to include constraints, which is particularly useful for labels and other views whose width and height are related to each other.

let labelSize = label.frameSize(thatFits: bounds.insetBy(dx: 20, dy: 20).size, constraints: [ .fixedWidth, .maxHeight ])
titleLabel.wrap(toFitWidth: boundsWidth, margins: 20)

UIView Distribution Extensions

Distribute a set of views vertically or horizontally using fixed and/or proportional spacing between them:

/// Vertically stack an icon, header, and button, with twice as much space at the bottom as the top.
selectionScreen.applySubviewDistribution([ 1.flexible, headerIcon, 8.fixed, headerLabel, 1.flexible, button, 2.flexible])

/// Left-align a pair of labels, one above the other, with equal space above the title and below the subtext (despite the subtext being a smaller font).
cell.applySubviewDistribution([ 1.flexible, titleLabel, 8.fixed, subtextLabel, 1.flexible ], alignment: .leading(inset: 10))

/// Adjust a "standard" distribution to filter out invisible views (hidden, alpha=0, uninstalled, or empty UILabels), and collapse adjacent spacers.
let distribution = ViewDistributionItem.collapsing(
    1.flexible,
    iconFPOView,
    Metrics.iconMargin.fixed,
    
    Metrics.titleTextMargin.fixed,
    titleLabel,
    Metrics.titleTextMargin.fixed,
    
    Metrics.subtextMargin.fixed,
    subtextLabel,
    1.flexible)

/// Equally size a pair of buttons with a hairline divider between them, and size/position them at the bottom of the alert.
alert.spreadOutSubviews([ cancelButton, acceptButton ], axis: .horizontal, margin: alert.hairlineWidth, inRect: alert.bounds.slice(from: .maxYEdge, amount: buttonHeight))

Debugging

Fixing layout issues is as simple as using the Xcode debugger. Remember that on a 2x device, view frame coordinates will be snapped to half-point boundaries (x.0 and x.5 only), while on 3x devices they are on 1/3-point boundaries (x.0, x.333, and x.667). The offsets used for view alignment do not need to be rounded (and generally shouldn’t be, to avoid accumulating rounding error), but view sizes should be.


Requirements

  • Xcode 10 / Swift 4.2
  • iOS 9.0 or later

Contributing

We’re glad you’re interested in Paralayout, and we’d love to see where you take it. Please read our contributing guidelines prior to submitting a pull request.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].