I'm trying to create a grid that displays about 5000 (static) thumbnails. To set up the grid, I'm using GridView library, which is a scrollview subclass that allows two dimensional scrolling.
This works fine when there are about 100-200 thumbs on the screen at once, but I'd like to add the ability to zoom in / out of the grid. This becomes when a problem when zooming out and the number of items increases to about 1000 on screen at once - the grid's scrolling lags heavily.
To display the thumbs, I'm using a UIView subclass that is inflated from a nib file that holds a UIImageview to display the cell's thumb.
I realize there are better ways to this, but I'm not sure where to start. How should I load cells into the grid if not from nibs? Should I use core graphics?
EDIT: Here's an example of the grid:
And here's the zoomed out grid:
The grid will need to display about 5000 elements on screen at once (the screenshot above is about 1500 elements). Here is the relevant code
// IN GRIDVIEW'S DATASOURCE & DELEGATES
func gridView(_ gridView: GridView, cellForRowAt indexPath: IndexPath) -> GridViewCell {
// this function sets up each cell
let cell = gridView.dequeueReusableCell(withReuseIdentifier: "GridCell", for: indexPath)
if let cell = cell as? GridCell {
cell.configure(indexPath.row, indexPath.section)
}
return cell
}
// GRIDCELL DECLARATION
class GridCell: GridViewCell {
@IBOutlet weak var image: UIImageView!
static var nib: UINib {
return UINib(nibName: "GridCell", bundle: Bundle(for: self))
}
func configure(_ row: Int, _ section: Int) {
// this function will sets up the thumbnails. As an example, we're changing the background color of cells in odd rows
if (row % 2 == 1) {
self.backgroundColor = .gray
}
else {
self.backgroundColor = .white
}
}
}