我正在尝试将我的XIB文件加载到UIView中但我遇到了一些麻烦.我有所需的覆盖功能,但它们似乎崩溃了.说出这个错误,警告:
could not load any Objective-C class information. This will
significantly reduce the quality of type information available.
我想知道是否有人可以告诉我如何将XIB文件正确加载到UIView中
import UIKit class Widget: UIView { let view = UIView() override init(frame: CGRect) { super.init(frame: frame) //call function loadNib() } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) loadNib() //fatalError("init(coder:) has not been implemented") } func loadNib() { let bundle = NSBundle(forClass: self.dynamicType) let nib = UINib(nibName: "nib",bundle: bundle) let view = nib.instantiateWithOwner(self,options: nil)[0] as! UIView view.frame = bounds view.autoresizingMask = [.FlexibleWidth,.FlexibleHeight] self.addSubview(view); } }
我在我们的一个项目中使用它,maby对你有用
原文链接:https://www.f2er.com/swift/320233.htmlimport UIKit class RegisterPageView: UIView { class func instanceFromNib() -> RegisterPageView { return UINib(nibName: "RegisterPageView",bundle: nil).instantiateWithOwner(nil,options: nil)[0] as! RegisterPageView } }