Skip to content

Instantly share code, notes, and snippets.

@douglastaquary
Created November 5, 2017 13:14
Show Gist options
  • Select an option

  • Save douglastaquary/9cda1e792c1383ef94218c71b7ea632f to your computer and use it in GitHub Desktop.

Select an option

Save douglastaquary/9cda1e792c1383ef94218c71b7ea632f to your computer and use it in GitHub Desktop.
//
// ConceptLayout.swift
// Concept-Elements-Swift
//
// Created by Douglas Taquary on 05/11/17.
// Copyright © 2017. All rights reserved.
//
import UIKit
public class ConceptLayout {
/**
Returns an array of constraints
*/
public class func constraints(_ visualFormat:String, views:[String:AnyObject]) -> [NSLayoutConstraint]
{
return NSLayoutConstraint.constraints(withVisualFormat: visualFormat, options: [], metrics: nil, views: views)
}
/**
Returns an constraint between two views
*/
public class func constraintTo(_ item:AnyObject, toItem:AnyObject?, align:NSLayoutAttribute, multiplier: CGFloat = 1, constant: CGFloat = 0 ) -> NSLayoutConstraint
{
return NSLayoutConstraint(item: item, attribute: align, relatedBy: .equal, toItem: toItem, attribute: align, multiplier: multiplier, constant: constant)
}
/// - Parameters:
/// - item: UIView for the constraint.
/// - attribute: NSLayoutAttribute enum value which the constraint will be created
/// - Parameter value: CGFloat value for the attribute constant value
/// - Returns: NSLayoutConstraint created
public class func constraintFor(_ item: UIView, attribute: NSLayoutAttribute, value: CGFloat) -> NSLayoutConstraint {
return NSLayoutConstraint(item: item, attribute: attribute, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment