How to programmatically duplicate UIViews built into an interface builder?

I want to create a sub-UIView in the interface builder (contained in UIScrollView) with some contained UILabels, then I want to programmatically “copy” this view, adjust its left position (multiple of its width) to achieve a “floating” left effect inside the UIScrollView. Then I want to add this copied UIView back to the UIScrollView with different text for UILabels.

The problem is that I don’t know how and if you can "copy" UIViews.

+3
source share
2 answers

[ ], , . , , NSKeyedArchiver/NSKeyedUnarchiver / , .

, , :

  • , , .
  • "" ( ).
  • IBOutlet, "myView" - , .
  • - :

-(UIView)makeMeANewMyView {
  // Load MyView.nib into the myView outlet.
  [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self];
  // Take ownership.
  UIView * view = [[self.myView retain] autorelease];
  self.myView = nil;
  return view;
}
+3

objective-c ( ). , , , , "" - , , , , -, . , UIView, ?

, , ... noob objective-c , !

+2

Source: https://habr.com/ru/post/1749497/


All Articles