-
Notifications
You must be signed in to change notification settings - Fork 0
/
APJNibView.swift
49 lines (43 loc) · 1.61 KB
/
APJNibView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// APJNibView.swift
// APJCommonClasses
//
// Created by Pino, Angelo on 27/12/2018.
//
import UIKit
open class APJNibView: UIView {
var view: UIView!
override init(frame: CGRect) {
super.init(frame: frame)
_xibSetup()
}
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
_xibSetup()
}
// MARK: private methods
private func _xibSetup() {
backgroundColor = UIColor.clear
view = loadNib()
view.frame = bounds
addSubview(view)
view.translatesAutoresizingMaskIntoConstraints = false
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[childView]|",
options: [],
metrics: nil,
views: ["childView": view!]))
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[childView]|",
options: [],
metrics: nil,
views: ["childView": view!]))
}
}
private extension UIView {
/** Loads instance from nib with the same name. */
func loadNib() -> UIView {
let bundle = Bundle(for: type(of: self))
let nibName = type(of: self).description().components(separatedBy: ".").last!
let nib = UINib(nibName: nibName, bundle: bundle)
return nib.instantiate(withOwner: self, options: nil).first as! UIView
}
}