I want to create a dynamic grid using for loop but I can't. I create demo here but it is not work and I can't understand the logic of this because I'm new in this.
It is important that I have to use for loop no others. So please give me any solutions using for loop. This is in my viewDidLoad method.
int x=5;
int y=5;
int hei=50;
int wid=50;
for (int i=0; i<3; i++)
{
for(int j=0;j<3;j++)
{
if (i==0 && j==0)
{
imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(x, y, wid, hei)];
[imageView1 setImage:[UIImage imageNamed:@"Motocross.png"]];
[self.view addSubview:imageView1];
}
else
{
imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(x+wid+5, y+hei+5, wid, hei)];
[imageView1 setImage:[UIImage imageNamed:@"Motocross.png"]];
[self.view addSubview:imageView1];
}
}
}
In that I want to create dynamic grid and the size of UIimageView is 50*50 and the space between UIImageView is 5. So in demo I generates only 3*3 grid (same as gallery in mobile).