Jab
Jab

Reputation: 27515

How to populate a UIScrollView with UIImageView's lines up in a row

I need some code on how to make a UIScrollView that contains UIImageViews lined up like the iPhone photo's app that comes with the phone.

Upvotes: 0

Views: 2039

Answers (2)

Noah Witherspoon
Noah Witherspoon

Reputation: 57149

Best way to do this is probably a standard UITableView whose cells contain a row of four UIImageViews. In -tableView:cellForRowAtIndexPath:, load the four images corresponding to that row (assuming you've got them in a linear array, the image indices would be (row*4), (row*4 + 1), (row*4 + 2), and (row*4 + 3)), and apply them to the cell's image views. Make sure to use -dequeueReusableCellWithIdentifier and initWithStyle:reuseIdentifier: or your performance—specifically, the overhead of creating and destroying all the views involved—will be terrible.

Upvotes: 2

Related Questions