Sourabh
Sourabh

Reputation: 5170

How to generate buttons using a for loop in ipad application?

I would like to generate buttons using a for loop.

Something like this:

button[] button = new button[10];
for(i=0;i<20;i++)
{
button[i].text = "some text";
}

Could someone please suggest a way to do this?

Upvotes: 1

Views: 276

Answers (1)

Ole Begemann
Ole Begemann

Reputation: 135540

for (int i=0; i < 20; i++) {
    UIButton *button = [UIButton buttonWithType:...];
    button.frame = CGRectMake(...);
    [self.view addSubview:button];
}

Upvotes: 1

Related Questions