使用视图 iOS、Swift 分配控件

Assign controls with view iOS, Swift

我有一个问题,有什么方法可以在我的自定义 UIView class 中制作类似 outlet 的东西。我通过

将视图与 class 连接
class func instanceFromNib() -> UIView {
        return UINib(nibName: "AddressView", bundle: nil).instantiate(withOwner: nil, options: nil)[0] as! UIView
    }

我整个class长得像

class AddressView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        var view = AddressView.instanceFromNib()
        self.addSubview(view)
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        var view = AddressView.instanceFromNib()

        self.addSubview(view)
    }

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

如果 AddressView 是 UIViewController 的子class 并且您将 class AddressView 设为 xib(从您的 Identity Inspector 选择 AddressView 作为自定义 class xib 文件的所有者)