2013-01-07 56 views
-5

对不起,我的英语。如何从循环添加UILabel?

我想显示以字符分隔的单词。我在包含单个字符的“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; 
     } 

    } 
} 
+3

这是什么结果?你在哪里遇到问题? – Nick

+0

请详细询问您的问题......我们通过此代码了解什么?你想找出什么? –

+0

[动态更新UILabel]的可能重复(http://stackoverflow.com/q/6336991/),[在循环中更新UILabel](http://stackoverflow.com/questions/8707388/updating-uilabel-in - 循环/ 8707418#8707418) –

回答

0

实际上你应该创建标签并将它放在你的视图上。

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];