Currently i am referring to this post and am able to create a 2*2 grid view
int rows = 2;
int cols = 2;
float gridWidth = 1024.0;
float gridHeight = 1024.0;
float buttonWidth = 100.0;
float buttonHeight = 100.0;
// float gapHorizontal = (gridWidth - (buttonWidth * rows)) / (rows + 1);
// float gapVertical = (gridHeight - (buttonHeight * cols)) / (cols + 1);
float gapHorizontal = 40;
float gapVertical = 40;
float offsetX;
float offsetY;
int count = 0;
do {
offsetX = gapHorizontal + ((count % rows) * (buttonWidth + gapHorizontal));
offsetY = gapVertical + ((count / rows) * (buttonHeight + gapVertical));
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(offsetX, offsetY, buttonWidth, buttonHeight)];
view.backgroundColor = [UIColor yellowColor];
[self.view addSubview:view];
offsetX+= buttonWidth + gapHorizontal;
count++;
} while(count < rows * cols);
But when I am try to create a 2*1 grid view
By changing this to
int rows = 2;
int cols = 1;
I’m not able to do so. Its only creating 2 views.
Is there any simple solution available for this?
What you describe is the expected behavior. Two rows with one column is exactly two cells, or its representation views.