Reputation: 616
First, I have an item that I draw with UIView . I want to draw the 20 items that one row has 4 items so there is 5 rows.My question is how can I find or calculate all positions of Item.
Upvotes: 0
Views: 43
Reputation:
Assuming an iPhone:
const float itemWidth = 320.0 / 4;
const float itemHeight = 480.0 / 4;
for (int row = 0; row < 5; row++)
for (int col = 0; col < 4; col++)
{
CGRect frm = CGRectMake(col * itemWidth, row * itemHeight, itemWidth, itemHeight);
// frm contains the position and size of each element
}
Needs adjustment for iPad or if you want padding between the elements.
Upvotes: 2