Hello,
I'm using a UITableView with cell style of UITableViewCellStyleValue1. I'm want to have multiple lines in the detailTextLabel, is that possible? and how? Or do I have to make a custom cell.
Any help is appreciated. Thanks, Mohsen
Hello,
I'm using a UITableView with cell style of UITableViewCellStyleValue1. I'm want to have multiple lines in the detailTextLabel, is that possible? and how? Or do I have to make a custom cell.
Any help is appreciated. Thanks, Mohsen
The detailTextLabel is a UILabel, the word wrapping rules apply just like with a label you create.
EDIT: Just thought, you'll also need to change the height of the cell if the text gets beyond some threshold of lines. probably 2 or 3 is okay.
You can set cell.detailTextLabel.numberOfLines = 2
to get 2 lines in there. However, I doubt UITableViewCell will lay out the labels as you expect in that case. You may want to subclass UITableViewCell and override -layoutSubviews
to position the labels how you want. You can call [super layoutSubviews]
and then just tweak the positions of the labels. You'll probably want to use -[NSString sizeWithFont:constrainedToSize:lineBreakMode:]
to calculate the correct size for the detail text label.
Alternatively, instead of subclassing UITableViewCell, you could try doing the tweaks in -tableView:willDisplayCell:forRowAtIndexPath:
, though if the cell ever decides it needs to re-layout, then your tweaks will be erased. I recommend you go with the subclassing approach.
Edit: BTW, with the subclass approach, all you have to do is change [UITableViewCell alloc]
to [MyTableViewCellSubclass alloc]
. Since you're not introducing new methods or properties, the variable can still remain typed as a UITableViewCell and you won't have to change any other code.