While there are ways to copy view hierarchies, they are hacky and should be avoided.
سؤال
Is there any easy way to copy an existing UI Control attribute from one to the other? Something like
*button1 = *button2;
I know that the above will not work, but just curious.
Yes, Yes, I know can use an XIB with a view with UIControl and create controls that way.
المحلول
نصائح أخرى
NSKeyedArchiver & NSKeyedUnarchiver work well for me in most cases. I've never tried to clone a control with complicated structure though.
extension UIView {
func deepCopy() -> UIView {
let data = NSKeyedArchiver.archivedDataWithRootObject(self)
let copy = NSKeyedUnarchiver.unarchiveObjectWithData(data)! as! UIView
return copy
}
}
لا تنتمي إلى StackOverflow