views:

35

answers:

1

Hi guys.

I have this interface with multiple UILabels. On view loading i populate white labelled values with some data from a db. The problem is, some of that fields are potentially too long for the interface, so i'd like to compute the total height of one label once the text is word wrapped and reposition the 2 labels below (shifting the Y coordinate) accordingly to the previous label's height.

All of this should go inside a UIScrollView to let the user scroll those labels vertically.

Any chance i can do this easily with some control i still don't know, or do i have to do it manually?

Thanks

A: 

You'll need to use the NSString UIKit Additions to compute the height you need to set on your UILabel, and then adjust the other controls appropriately.

Specifically, I think you want to use sizeWithFont:forWidth:lineBreakMode: to get the rect for your UILabel.


Alternatively, you could use a UIWebView and display the information as HTML. I don't know if it's necessarily less work, but you'll get a layout that automatically adjusts to the size of its contents.

Robot K