iOS:swift xib 嵌套

2020-11-17  本文已影响0人  Liu____

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

上一篇 下一篇

猜你喜欢

热点阅读