iOS动态创建UILabels [英] iOS create UILabels dynamically

查看:118
本文介绍了iOS动态创建UILabels的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,我希望我的观点包含5 UILabel s,有时3,有时 n



UILabels的数量取决于从网站获取的数据。

解决方案

你必须让他们(int i = 0; i {$($ i $)


$ b UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(/ *你想要的地方* /)];
label.text = @text; // etc ...
[self.view addSubview:label];
[标签发布];
}


Sometimes I want my view to contain 5 UILabels, sometimes 3 and sometimes n.

The number of UILabels depends on data that's fetched from a website.

解决方案

You'll have to make them in code instead of interface builder

 for (int i = 0; i < n; i++)
 {
    UILabel *label =  [[UILabel alloc] initWithFrame: CGRectMake(/* where you want it*/)];
    label.text = @"text"; //etc...
    [self.view addSubview:label];
    [label release];
 }

这篇关于iOS动态创建UILabels的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆