Duplicate, clone or copy UIView

后端 未结 4 2187
失恋的感觉
失恋的感觉 2020-12-29 04:45

I have a UIView that is linked to a UIViewController via the Interface Builder. Is it possible to duplicate, clone or copy this view so that I can use it more than once?

4条回答
  •  梦谈多话
    2020-12-29 05:21

    You can try with Swift 3.0.1 below:

    extension UIView{
    func copyView() -> AnyObject{
        return NSKeyedUnarchiver.unarchiveObject(with: NSKeyedArchiver.archivedData(withRootObject: self))! as AnyObject
     }
    }
    

提交回复
热议问题