0

Given a collection of Word objects, I want to display a scrollable tag cloud similar to what is shown below. My Word class has properties for Name and Rank from which I will determine sorting and weighting of the fonts. Each word should be a selectable object (for invoking some event). Since the collection can contain thousands of objects, I only need to manage words that are currently presented in the view (i.e., as they scroll off the bottom or top of the screen, I no longer care about them).

How would you approach this?

alt text

Bama91
  • 884
  • 2
  • 10
  • 24

2 Answers2

3

Put HTML-formatted text into a UIWebView with some JavaScript that scrolls on some timed basis. You might be able to handle touch events on elements via a JavaScript bridge.

Failing that, you'll need a bunch of UILabel elements of various sizes, and a layout manager that positions them appropriately, which will almost certainly be a lot more work.

Community
  • 1
  • 1
Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
  • 1
    +1 Web views are a nice solution especially seeing as tag clouds are well-known HTML widgets. – BoltClock Nov 16 '10 at 02:05
  • 2
    UIWebView sounds like an easy but expensive way to solve this problem. It should be fun to do in quartz :) – fhj Nov 16 '10 at 05:30
  • The UIWebView might work for a relatively small list of words. My app is an anagrammer that might return tens of thousands of results. I need a good way to manage a best-fit layout of individual labels of varying sizes with the ability to quickly flick through the list... like you would with a UITableView. – Bama91 Nov 16 '10 at 05:35
  • ...Where I am getting stuck is how to give the illusion of scrolling through a very long list while actually only managing labels for the words in view. – Bama91 Nov 16 '10 at 05:50
  • 1
    Perhaps use JavaScript to load only the content you need as the user scrolls through the list. Or perhaps look into a UIKit, CoreGraphics or Open GL approach. You'll need to manage everything yourself with those approaches. – Alex Reynolds Nov 16 '10 at 12:03
2

I ended up using a UITableView with a custom UITableViewCell containing an array of custom labels. With proper use of lazy loading and background processing, it is plenty fast. I'll go ahead and mark mine as the accepted answer, but I do appreciate all of the responses.

Bama91
  • 884
  • 2
  • 10
  • 24
  • Would you be willing to share the code that does this. I'd very much like to do the same in an app I'm working on. Happy to attribute to you in the app as well. – Kolya Miller May 19 '11 at 01:50