我想从代码中以编程方式动态地将UILabel控件添加到我的应用程序中,请帮帮我
答案 0 :(得分:4)
您可以在其中一种视图控制器方法中执行以下操作:
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