我使用 Storyboard,我想以编程方式复制现有的 UIView(以及所有“孩子”,如 UILabels)并将其添加到 ScrollView。因此,首先我为该视图(EventView)创建了一个自定义 UIView-Class,在其中我通过使用标签标识它们来初始化 UILabel 的新文本。现在我想将这些 EventViews 添加到这样的 Scrollview 中:
CGRect rect = CGRectMake(0.0, 0.0, 320, 320*10);
UIView *theView = [[UIView alloc] initWithFrame:rect];
for (int i = 0; i<10; i++)
{
CGRect rC = CGRectMake(0.0, 320*i, 320, 320);
EventView *dV = [[EventView alloc] initWithFrame:rC];
[dV inWithEvent:allEvents[i]];//Strings for the UILabels
[theView addSubview:dV];
}
theScrollView.contentSize = rect.size;
[theScrollView addSubview:theView];
}
有更好的(和有效的)解决方案吗?谢谢!