views:

339

answers:

3

As far as I can see (correct me if I'm wrong), there seems to be no obvious way to have a scrolling page of styled text (diff fonts, weight, sizes, colors etc of text) on the iPhone without resorting to a UIWebView, which seems to take quite a bit of memory and resources (and the scrolling isn't as smooth as a UITableView).

Is there a good, lightweight option for scrolling styled text for the iPhone?

+1  A: 

The UITableView is actually built upon the UIScrollView.

UIScrollView Class Reference

The way I have used UIScrollView in the past was to programatically add the subviews to the UIScrollView's contentView (such as UILabels, UIImagesViews, etc.) while keeping track of how much vertical space (height) the subviews and spacing between them are taking up. At the end of adding the UIScrollView's subviews you set the UIScollView's content view.

#define kFixedHorizontalSize 320.0
#define kNarutalScreenHeight 416.0
#define kViewSpacing 15.0

...

- (void)repopulateScrollView
{
    CGFloat yDrawHeight = 0.0;

    //add subviews, track yDrawHeight

   //for each sub view do something like
   yDrawHeight += [subviewAdded frame].size.height;
   yDrawHeight += kViewSpacing;

    ...

    CGSize contentSize = CGSizeMake(kFixedHorizontalSize, yDrawHeight < kNaturalScreenHeight ? kNaturalScreenHeight : yDrawHeight);
    [[self scrollView] setContentSize:contentSize]; 
}

Hope that helps!

awolf
+1  A: 

From my research, you have basically 2 real options:

  • Joe Hewitt's Three20 project offers a good amount of styled text support
  • You can write your own.

I agree that UIWebView is just too heavy weight for this, in many cases. We usually opt for (b), above, but I have heard good things about Three20.

Ben Gottlieb
+2  A: 

I'll echo Ben's answer a bit and point out that Three20 has solid support for exactly what you're looking for.

Check out the GitHub repo.

Style documentation can be found at http://three20.info/api/TTStyle, though for now the TTCatalog example in the examples directory of Three20 will give you the best example. Check out "Styled Labels" in the TTCatalog app.

If you have any troubles styling your text, we have an active group of supportive developers at the Three20 google group.

featherless