Skip to content

Instantly share code, notes, and snippets.

@richy486
Last active September 5, 2016 18:20
Show Gist options
  • Save richy486/b95786706276fd58c4dfe811401090a7 to your computer and use it in GitHub Desktop.
Save richy486/b95786706276fd58c4dfe811401090a7 to your computer and use it in GitHub Desktop.
UIView+ConstraintsHelper.swift
//
// UIView+ConstraintsHelper.swift
//
// Created by Richard Adem on 5/17/16.
// Copyright © 2016 Richard Adem. All rights reserved.
//
import UIKit
struct VFLManager {
var options:NSLayoutFormatOptions
var metrics:[String : AnyObject]?
var views:[String : AnyObject]
var view:UIView
func add(vflString:String) {
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: vflString
, options: options
, metrics: metrics
, views: views))
}
}
extension UIView {
func setVFLWithOptions(options opts: NSLayoutFormatOptions
, metrics: [String : AnyObject]?
, views: [String : AnyObject]
, block: (_:VFLManager) -> ()){
let vflManager = VFLManager(options: opts, metrics: metrics, views: views, view: self)
block(vflManager)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment