I create a custom UIView Object using the interface builder. This view contains a UILabel and an UIImageView.
I placed this object using interface builder in a ViewController and set the class of the UIView to UIViewLabelImage. I referenced the UILabel and an UIImageView in that class .h file . I also create a CustomOutlet to manipulate this new UIViewLabelImage Object.
I managed to retrieve the object UIViewLabelImage using :
UIViewLabelImage *view = (UIViewLabelImage *)[self.view viewWithTag:101];
//or using self.CustomOutlet.
I’am able to change the view, the text and image everything works great.
self.CustomOutlet.img.backgroundColor = [UIColor redColor];
If i want to add another UIViewLabelImage programmatically it works too. I Retrieve that newly created object using the new tag for example.
But i have a problem when i try to copy the UIViewLabelImage. The copy work and the object presented on the screen is the same as the first one but i am not able to change the text or image of that label. This is because the copyOFLabel.text and copyOFLabel.img are nil.
UIViewLabelImage *copyOFLabel = [NSKeyedUnarchiver unarchiveObjectWithData:
[NSKeyedArchiver archivedDataWithRootObject:self.CustomOutlet]];
copyOFLabel.tag = 11;
//copyOfLabel.text == nil
copyOFLabel.text.text = @"Copy Label";
copyOFLabel.backgroundColor = [UIColor greenColor];
copyOFLabel.frame = CGRectOffset(copyOFLabel.frame, 100, 200);
//view Added same as self.CustomOutlet expect for the background color set to green
[self.view addSubview:copyOFLabel];
Is there a way to copy that UIViewLabelImage and keep the image and text referenced in the text and img properties of the UIViewLabelImage variable ?