Giter Club home page Giter Club logo

lyt's Introduction

Lyt

Version Platform Build Status

A UIView and NSView category to make autolayout (more) readable and less verbose. For iOS and OS X.

###Better semantics with less code

Lyt allows you to express the intent of your constraint. Write this:

[view lyt_centerInParent];

Instead of:

NSLayoutConstraint *centerXConstraint = [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:view.superview attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0];
[view.superview addConstraint:centerXConstraint];

NSLayoutConstraint *centerYConstraint = [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:view2 attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0];
[view.superview addConstraint:centerYConstraint];

Or this:

[view lyt_alignSidesToParentWithMargin:10];

Instead of:

NSDictionary *views = NSDictionaryOfVariableBindings(view);
NSDictionary *metrics = @{@"margin" : @(10)};
NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-margin-[view]-margin-|" options:kNilOptions metrics:metrics views:views];
[view.superview addConstraints:constraints];

###Designed for code completion

Type lyt_ and then the layout action you want (e.g., center) to see what's available.

Code completion screenshot

Lyt offers dozens of methods. Current families are:

  • lyt_align*
  • lyt_center*
  • lyt_place*
  • lyt_set*
  • lyt_match*

###Support for dynamic layouts

Each Lyt method returns the corresponding constraint or constraints, which you can then modify or remove from the view hierarchy.

NSLayoutConstraint *leftConstraint = [view lyt_alignLeftToParent];
// Later...
leftConstraint.constant = 10; 

Additionally, each method has an equivalent that doesn't add the constraint to the view hierarchy, which is particularly useful for dynamic autolayouts. For example:

_labelLeftConstraint = [_label lyt_constraintByAligningLeftToParent];
// Later...
[self.view addConstraint:_labelLeftConstraint]; 

##Installation

Using CocoaPods:

pod 'Lyt', '~> 0.3'

Or add the files from the Lyt directory if you're doing it manually.

##License

Copyright 2014 Robot Media SL

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

lyt's People

Contributors

hpique avatar vilanovi avatar

Watchers

AAA avatar 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.