You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.9 KiB
62 lines
1.9 KiB
//
|
|
// Created by Marco Schmickler on 25.05.15.
|
|
// Copyright (c) 2015 Marco Schmickler. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
|
|
public extension UIView {
|
|
|
|
func autolayout(_ views: [String:UIView?], constraints: Any...) {
|
|
autolay(views, constraints:constraints)
|
|
}
|
|
|
|
func autolay(_ views: [String:UIView?], constraints: [Any]) {
|
|
var index = 0;
|
|
|
|
for value in views.values {
|
|
let vv: UIView = value!
|
|
addSubview(vv)
|
|
vv.translatesAutoresizingMaskIntoConstraints = false
|
|
}
|
|
|
|
while index < constraints.count {
|
|
let c = constraints[index]
|
|
if c is String {
|
|
if index + 1 < constraints.count && !(constraints[index + 1] is String) {
|
|
index += 1
|
|
let constr: NSArray = NSLayoutConstraint.constraints(withVisualFormat: c as! String,
|
|
options: constraints[index] as! NSLayoutConstraint.FormatOptions,
|
|
metrics: nil,
|
|
views: views) as NSArray
|
|
addConstraints(constr as! [NSLayoutConstraint])
|
|
} else {
|
|
let constr: NSArray = NSLayoutConstraint.constraints(withVisualFormat: c as! String,
|
|
options: NSLayoutConstraint.FormatOptions(rawValue: 0), metrics: nil, views: views) as NSArray
|
|
addConstraints(constr as! [NSLayoutConstraint])
|
|
}
|
|
}
|
|
index+=1
|
|
}
|
|
}
|
|
|
|
func recursiveSearchForViewWithName(_ classname: String) -> UIView? {
|
|
for v in subviews {
|
|
let sv = v
|
|
let result = sv.recursiveSearchForViewWithName(classname)
|
|
let cn = String(describing: type(of: v))
|
|
|
|
if cn == classname {
|
|
return v
|
|
}
|
|
|
|
if result != nil {
|
|
return result
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
|
|
}
|