美文网首页
iOS 为类添加xib文件绑定

iOS 为类添加xib文件绑定

作者: gaookey | 来源:发表于2020-06-29 17:25 被阅读0次

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

image.png

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

image.png

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

image.png

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

image.png

2020.06.29 更新

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

image.png

在类中添加获取xib方法

import UIKit

class SPView: UIView {
    
    static func shareView() -> SPView {
        return Bundle.main.loadNibNamed("SPView", owner: self, options: nil)?.first as! SPView
    }
}

相关文章

网友评论

      本文标题:iOS 为类添加xib文件绑定

      本文链接:https://www.haomeiwen.com/subject/yucafktx.html