Objective c 如何从循环中添加UILabel?

Objective c 如何从循环中添加UILabel?,objective-c,ios,xcode,uikit,Objective C,Ios,Xcode,Uikit,对不起我的英语 我想显示以字符分隔的单词。我在“chars”数组中有包含单个字符的不同字符串。我试过这个: int x = 20; int y = 20; int screenx = self.view.bounds.size.width - 14; for (NSString *string in chars){ for (int i=0; i<messageLength; i++) { UILabel *display; display.text

对不起我的英语

我想显示以字符分隔的单词。我在“chars”数组中有包含单个字符的不同字符串。我试过这个:

int x = 20;
int y = 20;
int screenx = self.view.bounds.size.width - 14;
for (NSString *string in chars){
    for (int i=0; i<messageLength; i++) {
        UILabel *display;
        display.text = [chars objectAtIndex:i];
        display.frame = CGRectMake(x, y, 14, 22);
        display.textColor = [UIColor whiteColor];
        x = x + 14;
        if (x >= screenx){
            x = 20;
            y = y + 20;
        }

    }
}
intx=20;
int y=20;
int screenx=self.view.bounds.size.width-14;
for(NSString*字符中的字符串){
对于(int i=0;i=screenx){
x=20;
y=y+20;
}
}
}

您应该实际创建标签并将其放置在视图上

UILabel *display = [[UILabel alloc] init];
display.text = [chars objectAtIndex:i];
display.frame = CGRectMake(x, y, 14, 22);
display.textColor = [UIColor whiteColor];
[self.view addSubView:display];

结果如何?你哪里有问题?请详细询问你的问题。。。我们对该代码的理解是什么?您想要了解的内容???可能重复,请删除内部for循环并使用UILabel*display=[[UILabel alloc]init];display.text=字符串;结果是出现了一个黑屏:(,问题是我创建的uilabel没有出现在视图中。我想要的是具有不同字符的不同标签。