Coder Social home page Coder Social logo

shinpurulayout's Introduction

ShinpuruLayout

Simple Layout in Swift using HGroups & VGroups

/ShinpuruLayout/softimage_screen.png

#Introduction

Shinpuru Layout allows developers to layout user interface elements using horizontal and vertical groups. Items in groups can be sized in absolute points or relative percentages and groups may be nested.

#Installation

To install Shinpuru Layout for use in your own project, simply copy SLControls.swift and SLGroup.swift

#Usage

To begin a Shinpuru screen, create a top level container, for horizontal layout:

let group = SLHGroup()

...and for vertical layout:

let group = SLVGroup()

This top level group needs to be anchored to its superview's bounds:

override func viewDidLayoutSubviews()
{
    let top = topLayoutGuide.length
    let bottom = bottomLayoutGuide.length
        
    group.frame = CGRect(x: 0, y: top, width: view.frame.width, height: view.frame.height - top - bottom).rectByInsetting(dx: 10, dy: 10)
}

Child elements can be added either though the group's children array:

for i: Int in 1 ... 10
{
  group.children.append(UILabel())
}

...or with addSubView:

group.addSubview(UILabel())

Standard controls will be spaced evenly across the entire width or height of their parent container.

You can subclass UIView based components and have them implement SLLayoutItem for more control over sizing. SLLayoutItem has two properties:

  • percentageSize - defines the percentage width or height of the SLLayoutItem
  • explicitSize - ignored if percentageSize is not nil, but allows an absolute size in points for the SLLayoutItem

#Examples

This project ships with five demonstrations:

  • ComplexGrid - this was the file I used during build and test. The code is a bit messy, but it shows how a ludicrously complex grid can be built from a hierarchy of Shinpuru Layout groups
  • SoftimageLayout - a layout inspired by the venerable Softimage
  • AlignAndDistribute - a simple screen demonstrating left, centre and right align, along with evenly distributing components across the width of a container.
  • DepthOfField - my SceneKit depth of field demonstration updated to use Shinpuru for its layout.
  • CollectionView - laying out the contents of a UICollectionViewCell with Shinpuru

#Further Information

To learn how Shinpuru was build and see examples of different layouts, see my blog:

http://flexmonkey.blogspot.co.uk/2015/05/easy-group-based-layout-for-swift-with.html

shinpurulayout's People

Contributors

flexmonkey avatar

Watchers

James Cloos 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.