mirror of
https://github.com/lil-org/tokenary.git
synced 2024-12-13 17:44:07 +03:00
20 lines
847 B
Swift
20 lines
847 B
Swift
// Copyright © 2021 Tokenary. All rights reserved.
|
|
|
|
import UIKit
|
|
|
|
func loadNib<View: UIView>(_ type: View.Type) -> View {
|
|
return Bundle.main.loadNibNamed(String(describing: type), owner: nil, options: nil)![0] as! View
|
|
}
|
|
|
|
extension UIView {
|
|
|
|
func addSubviewConstrainedToFrame(_ subview: UIView) {
|
|
addSubview(subview)
|
|
subview.translatesAutoresizingMaskIntoConstraints = false
|
|
let firstConstraints = NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[subview]-0-|", options: .directionLeadingToTrailing, metrics: nil, views: ["subview": subview])
|
|
let secondConstraints = NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[subview]-0-|", options: .directionLeadingToTrailing, metrics: nil, views: ["subview": subview])
|
|
addConstraints(firstConstraints + secondConstraints)
|
|
}
|
|
|
|
}
|