加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

将XIB文件加载到UIView Swift

发布时间:2020-12-14 05:49:10 所属栏目:百科 来源:网络整理
导读:我正在尝试将我的XIB文件加载到UIView中但我遇到了一些麻烦.我有所需的覆盖功能,但它们似乎崩溃了.说出这个错误,警告: could not load any Objective-C class information. This will significantly reduce the quality of type information available. 我
我正在尝试将我的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对你有用
import UIKit

class RegisterPageView: UIView {

        class func instanceFromNib() -> RegisterPageView {
            return UINib(nibName: "RegisterPageView",bundle: nil).instantiateWithOwner(nil,options: nil)[0] as! RegisterPageView
        }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读