Add maltiple button using for loop

UIButton *btn; int xi,yi,b; b=1;
xi=10; yi=10;

for (int a=1; a<=5; a++)
{
for (int i=1; i<=5; i++)
{

btn=[[UIButton alloc]init];

btn.backgroundColor=[UIColor blueColor];

btn.frame=CGRectMake(xi, yi, 50, 50);

[btn setTag:b];

[btn addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:btn]; xi+=60;
b++;

}
yi+=60; xi=10;

}

Leave a comment