node ninja
node ninja

Reputation: 32986

How to put text on different lines in a table cell

In a table cell I tried putting "\n" in the text, but this doesn't put the text on a new line it just puts a space in between the text.

Upvotes: 0

Views: 414

Answers (3)

Raj Pawan Gumdal
Raj Pawan Gumdal

Reputation: 7438

Set the property cell.textLabel.numberOfLines to 0 lines, this will automatically calculate the number of lines needed to fit the text you have set to the text label.

You should not manually change the frame of the default textLabel of the cell since the frame of textLabel will be calculated intelligently based on whether image is set to the cell's imageView property or not.

Upvotes: 0

Lily Ballard
Lily Ballard

Reputation: 185663

You need to set the cell.textLabel.numberOfLines property to something other than 1. 0 means any number of lines, anything higher than 1 means capped at that number of lines. Also note that you'll need to implement the -tableView:heightForRowAtIndexPath: delegate method in order to resize your cells to fit the text, which may be a bit complicated since you won't know the precise metrics the cell uses to lay out the label.

Upvotes: 2

jer
jer

Reputation: 20236

Either use different labels, a different style (there's one style, I can't remember which one, which has two labels, one ontop of the other in terms of vertical space), or create your one label allowing at least 2 lines. Alternatively, you could use a text view instead. Many ways you can do this, even custom drawing the text. Pick your poison.

Upvotes: 0

Related Questions