【发布时间】:2009-10-21 06:46:06
【问题描述】:
我想通过代码(以编程方式)动态地将 UILabel 控件添加到我的应用程序中,请帮助我
【问题讨论】:
我想通过代码(以编程方式)动态地将 UILabel 控件添加到我的应用程序中,请帮助我
【问题讨论】:
您可以在其中一种视图控制器方法中执行以下操作:
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(...)]; // Create UILabel
myLabel.tag = someTag; // set label's tag to access this label in future via [view viewWithTag:someTag];
... // set label's properties like text, background and text color, font size etc (e.g. myLabel.textColor = [UIColor redColor];)
[view addSubView:myLabel]; // add label to your view
[myLabel release]; // view owns the label now so we can release it
【讨论】: