GithubHelp home page GithubHelp logo

kb100824 / classyliveautolayout Goto Github PK

View Code? Open in Web Editor NEW

This project forked from olegam/classylivelayout

0.0 1.0 0.0 311 KB

Use Classy stylesheets together with Masonry to tweak AutoLayout constants live when debugging in the simulator.

License: MIT License

Ruby 3.84% Objective-C 96.16%

classyliveautolayout's Introduction

Gif showing editing layout constants results in real time layout updates

Iterate blazingly fast when defining view layouts by putting your AutoLayout constants in a stylesheet file with live reloading. No need to recompile and restart the simulator when you change a constant.

Suplementary blogpost: http://codeblog.shape.dk/blog/2013/12/16/live-editing-layout-constants-using-classy/

This repository (and pod available through Cocoapods) contains the category UIView+ClassyLayoutProperties making it easy to define size and margin properties on views that can be set from a Classy stylesheet and trigger -updateConstraints that can then easily be implemented using Masonry's mas_updateConstraints:. This pod also contains a number of convenient methods making it easy and declarative to define layouts with constants taken from the stylesheet.

In your view's -updateConstraints method you define a layout like this:

// new shorthand notation to create constrains relative to the superview with constants from stylesheet
[_blueBoxView mas_updateConstraintsWidthFromStylesheet];
[_blueBoxView mas_updateConstraintsHeightFromStylesheet];
[_blueBoxView mas_updateConstraintsWithTopMarginRelativeToSuperview];
// or we can specify another view to set margins relative to:
[_blueBoxView mas_updateConstraintsWithLeftMarginRelativeTo:self];

In the stylesheet we set the constants implicitly referenced in the above layout code.

UIView.blue-box {
    background-color: blue;
    size: 120 80;
    margin-top: 110;
    margin-left: 50;
}

If you have set up live reloading in Classy the view will immediately update when you change the size and margin in the stylesheet. The best way to get started is to check out the demo project included in this repo.

There is also an example of how to use this with UITableViewCells and an abstract UICollectionView class that can be used to easily get this behavior in collection views.

classyliveautolayout's People

Contributors

olegam avatar samlaudev avatar

Watchers

 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.