如何从NSMutableArray动态创建uilabel?

Fab*_*bio 2 objective-c uilabel ios

NSMutableArray *items //包含15个项目

我需要把一个标签从另一个下来我尝试这样的东西但不起作用

int count=20;

for(int i = 0; i < [items count]; i++){
        UILabel *label =  [[UILabel alloc] initWithFrame: CGRectMake(0,0,0,count)];
        label.text = @"text"; //etc...
        count+=20;

        [_scroll addSubview:label];

    }
Run Code Online (Sandbox Code Playgroud)

我该怎么办谢谢

rma*_*ddy 5

您需要正确设置框架.

int count=20;

for(int i = 0; i < [items count]; i++){
    UILabel *label =  [[UILabel alloc] initWithFrame: CGRectMake(0,count,0,0)];
    label.text = @"text"; //etc...
    [label sizeToFit]; // resize the width and height to fit the text
    count+=20;

    [_scroll addSubview:label];
}
Run Code Online (Sandbox Code Playgroud)