我正在尝试将我的 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);
}
}
最佳答案
我在我们的一个项目中使用它,可能对你有用
import UIKit
class RegisterPageView: UIView {
class func instanceFromNib() -> RegisterPageView {
return UINib(nibName: "RegisterPageView", bundle: nil).instantiateWithOwner(nil, options: nil)[0] as! RegisterPageView
}
}
关于ios - 将 XIB 文件加载到 UIView Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35659714/