我将子视图添加到UIScrollView并使用xib文件。我想重写一遍,但使用故事板。我怎样才能重写这段代码?
for (unsigned i = 0; i < [glyphs count]; i++)
{
GlyphView *aView = [[[NSBundle mainBundle] loadNibNamed:@"GlyphView" owner:self options:nil] objectAtIndex:0];
aView.glyphLabel.text = [glyphs objectAtIndex:i];
aView.frame = CGRectMake(glyphScrollView.frame.size.width * i, 0, glyphScrollView.frame.size.width, glyphScrollView.frame.size.height);
[glyphScrollView addSubview:aView];
}
答案 0 :(得分:0)
我在此处http://www.codeproject.com/Tips/1069081/Independent-UIView-in-storyboard提供了有关如何在故事板中添加独立UIView
的提示。
您可以按照故事板中的上述教程添加UIView
,将UIView
课程映射到您的GlyphView
。
在控制器中有一个这个视图的IBoutlet。
现在,您在上面编写的代码将更改为如下所示。
for (unsigned i = 0; i < [glyphs count]; i++)
{
GlyphView *aView = self.glymphView;
aView.glyphLabel.text = [glyphs objectAtIndex:i];
aView.frame = CGRectMake(glyphScrollView.frame.size.width * i, 0, glyphScrollView.frame.size.width, glyphScrollView.frame.size.height);
[glyphScrollView addSubview:aView];
}