Take the 2-minute tour ×

I'm trying to figure out how to replicate the UITableViewCellStyleValue2 style so that the detail text can be multiple lines - as seen in the 'address' cells in the Contacts app. Like the Contacts app, some of the fields (like street name) are optional; so it would show say 3 lines instead of 4, if the street was not nil.

I'm I missing a trick, or do I have to create a custom cell in IB? How to ensure the text and detail text labels line-up with other UITableViewCellStyleValue2 cells?

Thanks for any tips.

share|improve this question
add comment

4 Answers

up vote 23 down vote accepted

Another round of searching found this:


Quickly tried it, and it works - just need to set the font size down a bit.

share|improve this answer
One problem now is that UILineBreakModeWordWrap is depreciated. Now you must use NSLineBreakByWordWrapping in iOS 6. –  Marcel Marino Nov 26 '13 at 14:43
add comment

It sounds to me like you'll have to create a custom UITableCell. The only way to ensure the text lines up is to get the margin/text width values correct, which can be done via trial and error, or using a measuring tool such as xScope.

share|improve this answer
add comment

I also had the problem that the textLabel and the detailTextLabel had a different position. Solution: For the detailTextLabel use the same height like the textLabel (e.g. 13)

share|improve this answer
add comment

Create a custom cell for you table and place a UILabel and a UITextView inside it. Position the label & text view to match their x,y positions to the other cells you are using in that table. You insert "\n" in the textview's text wherever you want line breaks to occur. You resize the textview height depending on the number of lines in the textview using something like:

CGRect frame = yourTextView.frame; frame.size.height = yourTextView.contentSize.height; yourTextView.frame = frame; return frame.size.height + 20.0; // Pad the cell's height as necessary for your applicaion

share|improve this answer
normally, it is hard to define where should put a line break. –  Raptor Oct 4 '11 at 10:34
add comment

Your Answer


