pratik
pratik

Reputation: 4489

iPhone + add controls dynamically

I want to add UILabel controls to my application dynamically from code (programmatically), please help me

Upvotes: 0

Views: 2293

Answers (1)

Vladimir
Vladimir

Reputation: 170849

You can do it the following way in one of the view controller methods:

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

Upvotes: 4

Related Questions