我想在Interface Builder中构建一个子UIView(包含在UIScrollView中),其中包含一些UILabel,然后我想以编程方式复制此视图调整其左侧位置(通过其宽度的倍数)来实现在UIScrollView中浮动左侧效果。然后,我想将这个复制的UIView添加回UILcrollView,并为UILabels添加不同的文本。
I want to build up a sub-UIView in Interface Builder (contained within a UIScrollView) with some UILabels contained, I then want to programmatically "copy" this view adjust its left position (by multiples of its width) to achieve a "floating" left effect inside a UIScrollView. I then want to add this copied UIView back into the UIScrollView with different text for the UILabels.
问题是我不知道如何以及如果你可以复制 UIViews。
The problem is I don't know how and if you can "copy" UIViews.
推荐答案您可以尝试调用[查看副本],但如果不起作用我也不会感到惊讶。您可以使用NSKeyedArchiver / NSKeyedUnarchiver来序列化/反序列化视图,但这也非常糟糕。
You can try calling [view copy], but I wouldn't be surprised if that didn't work. You can probably use NSKeyedArchiver/NSKeyedUnarchiver to serialize/deserialize the view, but that's also pretty terrible.
相反,您可能希望加载视图的多个副本:
Instead, you probably want to load multiple copies of the view:
-(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; }
更多推荐
如何以编程方式复制界面构建器中内置的UIViews?
发布评论