3

I want to create a TabItem in a TabBarController containing a grid of images which a user can select. I know I could use a TableViewController, but that would just show a long list, rather than rows of (for example) 3x4 images.

Is this possible?

Echilon
  • 10,064
  • 33
  • 131
  • 217
  • did u search for "grid", "view" and "cocoa-touch"? – vikingosegundo May 14 '11 at 16:38
  • 1
    You can use UIScrollView to create a grid of items. You can calculate the total width of the scroll view / num items in each row and add subviews onto the scrollview. If you want to display hundreds of subviews in a grid, you might have to implement your own dequeueing mechanism. – Mahadevan Sreenivasan May 14 '11 at 17:10
  • This question also proved useful in finding a solution to this problem: http://stackoverflow.com/questions/3622209/lazy-loading-of-subviews-into-a-non-paging-uiscrollview – Norman H Nov 02 '11 at 16:25

2 Answers2

7

Apple has sample code TiledScrollView.m that demonstrates how to do what you want to do. The guts of the tile reuse is in layoutSubviews. Obviously you will need to tweak it to your own tasks... but it's always nice to have some working code to start with ;-) Hope this helps.

idz
  • 12,825
  • 1
  • 29
  • 40
  • I think this is what you may have been referring to in your answer? http://developer.apple.com/library/ios/#samplecode/ScrollViewSuite/Listings/3_Tiling_Classes_TiledScrollView_m.html#//apple_ref/doc/uid/DTS40008904-3_Tiling_Classes_TiledScrollView_m-DontLinkElementID_26 – Norman H Nov 02 '11 at 16:24
  • This does look like an excellent starting point for anyone wanting to create a custom control, but in my case I went with one of the many GridView controls available. – Echilon Jan 18 '12 at 13:04
4

I eventually went with an excellent control from CocoaControls called DTGridView, but it was a close second to GMGridView, which was a close second. I found GMGridView a tad too powerful.

One of the things I found relatively easy to do with DTGridView was to override -(void)drawRect to add a stacked stack effect using CoreGraphics.

Echilon
  • 10,064
  • 33
  • 131
  • 217