49 lines
1.2 KiB
Swift
49 lines
1.2 KiB
Swift
//
|
|
// CommonViewCustom.swift
|
|
// List
|
|
//
|
|
// Created by Saveliy Stavitsky on 7/14/20.
|
|
// Copyright © 2020 Igor Danich. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
@IBDesignable class CommonViewCustom: UIView {
|
|
|
|
@IBOutlet var contentView: UIView!
|
|
|
|
func setup() {
|
|
contentView = loadViewFromNib()
|
|
if frame.size == .zero {
|
|
frame = contentView.bounds
|
|
} else {
|
|
contentView.frame = bounds
|
|
}
|
|
contentView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
addSubview(contentView)
|
|
}
|
|
|
|
func loadViewFromNib() -> UIView {
|
|
let bundle = Bundle(for: type(of: self))
|
|
let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
|
|
// swiftlint:disable force_cast
|
|
let view = nib.instantiate(withOwner: self, options: nil)[0] as! UIView
|
|
return view
|
|
}
|
|
|
|
func changeVisibility(_ isVisible: Bool) {
|
|
contentView.isHidden = !isVisible
|
|
}
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
setup()
|
|
}
|
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
super.init(coder: aDecoder)
|
|
setup()
|
|
}
|
|
|
|
}
|