views:

121

answers:

1
+1  Q: 

UIView duplicate

Hi!

I need to duplicate a view, with all it's subviews.

Does anyone knows how to do it?

Thanks in advance!

+2  A: 

The easiest (but probably not the fastest) way is to archive it into an NSData object and unarchive it right away.

NSData *tempArchive = [NSKeyedArchiver archivedDataWithRootObject:myView];
UIView *myViewDuplicate = [NSKeyedUnarchiver unarchiveObjectWithData:tempArchive];
Ole Begemann