将xib重新映射到故事板

时间:2016-01-18 22:48:10

标签: ios objective-c storyboard

我将子视图添加到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];
    }

1 个答案:

答案 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];
}