Giter VIP home page Giter VIP logo

simplelayout's Introduction

SimpleLayout

Version Platform License

Índice

Features

  • Easy to use
  • NSLayoutConstraint shortcuts

Screen Shots

Demo Example

Prerequisites

  • iOS 8+
  • Xcode 7+
  • Swift 3.0

Installation

SimpleLayout is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "SimpleLayout"

How to Use

Check out the demo project for a concrete example.

Example

let background = UIView()

background.backgroundColor = .greenColor()
view.addSubview(background)

SimpleLayout.addMarginZero(background, toItem: view)
// OR
// background.sl_addMarginZero(view)
// OR
// background.sl_addMargin(view, constant: 0)

API

Margin
let imgProfile = UIImageView()

imgProfile.image = UIImage(named: "yourimage")
view.addSubview(imgProfile)

SimpleLayout.addMarginTop(imgProfile, toItem: view, constant: 10)
SimpleLayout.addMarginLeft(imgProfile, toItem: view, constant: 10)
SimpleLayout.addMarginRight(imgProfile, toItem: view, constant: 10)
// OR
// imgProfile.sl_addMarginTop(view, constant: 10)
// imgProfile.sl_addMarginLeft(view, constant: 10)
// imgProfile.sl_addMarginRight(view, constant: 10)
// OR
// imgProfile.sl_addMarginTop(view, constant: 10)
// imgProfile.sl_addMarginLeading(view, constant: 10)
// imgProfile.sl_addMarginTrailing(view, constant: 10)
let lblFooter = UILabel()

lblFooter.text = "Copyright © 2016 YourApp. All rights reserved"
view.addSubview(lblFooter)

SimpleLayout.addMarginBottom(lblFooter, toItem: view, constant: 10)
SimpleLayout.addMarginLeft(lblFooter, toItem: view, constant: 10, relatedBy: .GreaterThanOrEqual)
SimpleLayout.addMarginRight(lblFooter, toItem: view, constant: 10, relatedBy: .GreaterThanOrEqual)
// OR
// lblFooter.sl_addMarginBottom(view, constant: 10)
// lblFooter.sl_addMarginLeft(view, constant: 10, relatedBy: .GreaterThanOrEqual)
// lblFooter.sl_addMarginRight(view, constant: 10, relatedBy: .GreaterThanOrEqual)
// OR
// lblFooter.sl_addMarginBottom(view, constant: 10)
// lblFooter.sl_addMarginLeading(view, constant: 10, relatedBy: .GreaterThanOrEqual)
// lblFooter.sl_addMarginTrailing(view, constant: 10, relatedBy: .GreaterThanOrEqual)
Origin
let lblName = UILabel()

lblName.text = "Pepito"
view.addSubview(lblName)

SimpleLayout.addCenter(lblName, toItem: view)
// OR
// lblName.sl_addCenter(view)
let lblFooter = UILabel()

lblFooter.text = "Copyright © 2016 YourApp. All rights reserved"
view.addSubview(lblFooter)

SimpleLayout.addCenterX(lblFooter, toItem: view)
SimpleLayout.addMarginBottom(lblFooter, toItem: view, constant: 10)
// OR
// lblFooter.sl_addCenterX(view)
// lblFooter.sl_addMarginBottom(view, constant: 10)
Size
let lblDescription = UILabel()

lblDescription.text = "Description to long..."
lblDescription.lineBreakMode = NSLineBreakMode.ByWordWrapping
lblDescription.numberOfLines = 0 // Infinite
view.addSubview(lblDescription)

SimpleLayout.addHeight(lblDescription, constant: 21, relatedBy: .GreaterThanOrEqual)
// OR
// lblDescription.sl_addHeight(21, relatedBy: .GreaterThanOrEqual)
let imgProfile = UIImageView()

imgProfile.image = UIImage(named: "yourimage")
view.addSubview(imgProfile)

SimpleLayout.addSize(imgProfile, constant: 175)
SimpleLayout.addCenter(imgProfile, toItem: view)
// OR
// imgProfile.sl_addSize(175)
// imgProfile.sl_addCenter(view)

License

SimpleLayout is available under the MIT license. See the LICENSE file for more info.

simplelayout's People

Contributors

nmolina-umewin avatar comodinx avatar

Stargazers

Andres Ciaño avatar Gonzalo Aizpún avatar Carabineiro avatar

Watchers

James Cloos avatar  avatar Carabineiro avatar Gonzalo Aizpún avatar

Forkers

carabina

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.