views:

549

answers:

2

I have a view with two UITextView elements in it, each of which is tied to an outlet in the controller. The content for these is coming from a database, and is sometimes short an other times long. I want it to look like it would in html, with <p>content1</p><p>content2</p>, such that the distances from the end of content1 to beginning of content2 is fixed, but content2 gets shifted down the page if content1 is long.

Seems like a very basic requirement but I can't quite figure out how to do it with Interface Builder. Would appreciate any help.

Thanks

+1  A: 

Interface builder doesn't support specifying relationships between sibling elements; the Cocoa layout engine does everything relative to the containing view.

I'd recommend creating a single UITextView that contains both paragraphs, inserting a single empty line between them. Keep each paragraph in its own instance variable, though, and when either one is updated, update the display as well, reconstructing the combined text from the two separate paragraphs.

BJ Homer
Yes, thanks. I ended up using UIWebView so that I can also apply formatting. But it seemed like a lame way of doing it. I think I could do it separately by calculating the bounding box size based upon the text (as I imagine the UIWebView rendering engine does), but it seemed there should be readily available libraries for doing that already.
LeftHem
A: 

You can use the textview's contentSize property to align them relative to each other. This property always reflects the size of the actual laid out text content.

Max Seelemann