Giter Club home page Giter Club logo

lay's Introduction

Computes a perfectly justified collection of elements for any given width while maintaining the source aspect ratio. This library aims to mimic the layout implementations found in:

At it's core, Lay applies the linear partitioning algorithm against the aspect ratios of each size element to compute the balanced layout.

Features

  • No cropping, source size aspect ratios will be maintained.
  • Flexible, works with any array of elements that conform to the Sizable protocol.
  • Swift 3.0

Checkout out the Example app to see how this can be integrated with UICollectionViews.

This project is heavily inspired by this article written by Johannes Treitz.

Usage

import Lay

let aspectRatios: [CGSize] = [
	.init(width: 100, height: 100),
	.init(width: 80, height: 120),
	.init(width: 100, height: 100),
	.init(width: 200, height: 200),
	.init(width: 80, height: 100),
	.init(width: 100, height: 120),
	.init(width: 100, height: 80)
]

// Can now use these sizes to render your elements however you want

let sizes: [CGSize] = aspectRatios.lay_justify(for: view.bounds.size.width)

>>> [
      (140.0, 140.0),
      (93.0, 140.0),
      (142.0, 140.0),
      (208.0, 208.0),
      (167.0, 208.0),
      (150.0, 180.0),
      (225.0, 180.0)
    ]

TODO

  • Tests
  • Cocoapods support

Requirements

  • Xcode 8.0+
  • iOS 9.0+
  • Swift 3.0

Installation

Carthage

For Carthage, add the following to your Cartfile:

github "min/Lay" ~> 0.1.0

lay's People

Contributors

min avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.