Assign xib to the UIView in Swift

前端 未结 9 1976
死守一世寂寞
死守一世寂寞 2020-11-30 20:11

in objective c it can be done in init method by

-(id)init{
    self = [[[NSBundle mainBundle] loadNibNamed:@\"ViewBtnWishList\" owner:0 options:nil]     obje         


        
9条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 20:36

    that may be a solution for you:

    Swift 3.x

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

    Swift 2.x

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

提交回复
热议问题