How to create a copy of uiview (not a pointer to the original uiview)

I want to create a copy UIView, and I do not want to use NSKeyedArchiver, because I often create a copy of many views, and use NSKeyedArchiverwas slow.

I heard about copyor initWithZone:, but Googling found it was not good for UIView. I do not need a copy pointing to the original view, because any changes made to it also make changes to the copied one UIView.

+5
source share
2 answers

You can copy the view using:

TheView *copyOfView =  (TheView *) [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:origionalTheView]];
0
source

Create a UIView category that can help you copy the view. Something like that:

- (id) copyView {
     UIView *a = [[UIView alloc]init];
     a.frame = self.frame;
     //set all other properties of the UIView
     return a; //return [a autorelease] if not using ARC
}
-4
source

All Articles