2
votes

I'm having issues with the vertical alignment in a UITableViewCell.

I'm using a right detail UITableViewCell in which the detailTextLabel contains multiple lines of text. By setting the number of lines to zero I've managed to get the detailTextLabel to show all the text. This causes however the (left) text label to align in the top left corner instead of the center of the UITableViewCell.

Is there a way to use a TableViewCell in which the detailTextLabel contains multiple lines (In this case 2), and having the primary text label vertically centered?

Current UITableViewCell alignment

1
You should create your own prototype cell if your use case is different - Simon McLoughlin
Did you try setting the vertical align of the label? cell.textLabel.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter - Dejan Skledar
@DejanSkledar I don't believe that contentVerticalAlignment is a property of a UITextLabel? - Berendschot
My bad, I mixed it up with the textField. - Dejan Skledar
I should work with just changing the height of the textLabel. - Dejan Skledar

1 Answers

-2
votes

You should use UIControlContentVerticalAlignmentCenter and make equal height of the two labels.

But I would prefer to create your own custom cell.