import UIKit
class YWBaseView: UIView {
required init?(coder: NSCoder) {
super.init(coder: coder)
loadNib()
}
func loadNib(){
if viewInitNib() != nil {
let contentView = viewInitNib()!.instantiate(withOwner: self, options: nil)[0] as! UIView
contentView.frame = self.bounds;
contentView.autoresizingMask = [.flexibleHeight,.flexibleWidth];
self.backgroundColor = .clear
self.addSubview(contentView)
}
}
func viewInitNib() -> UINib? {
if (Bundle.main.path(forResource: String(describing: type(of: self)), ofType: "nib") != nil) {
return UINib.init(nibName: String(describing: type(of: self)), bundle: nil)
}
return nil
}
}
}
https://www.jianshu.com/p/98f7ae035a7b
https://blog.csdn.net/SoftwareDoger/article/details/102794121
https://www.jianshu.com/p/50ee2ce6d513
网友评论