在新创建的xib文件中,右击xib文件中的 File`s Owner 会显示如下

此时应在右侧Class处填写对应的类名绑定

添加后右击xib文件中的 File`s Owner 显示如下

在新出现的view属性和view视图连线

2020.06.29 更新
创建类和xib文件,选中xib文件中的UIView,Custom Class
添加对应的类型,填写 Module
或者勾选 Inherit Module From Target

在类中添加获取xib方法
import UIKit
class SPView: UIView {
static func shareView() -> SPView {
return Bundle.main.loadNibNamed("SPView", owner: self, options: nil)?.first as! SPView
}
}
网友评论