views:

251

answers:

2

I am trying to make a UITableView. Table cells are done in style UITableViewCellStyleValue1.

When text in either textLabel or detailTextLabel is too long, it gets shortened with ellipsis... This happens for both labels; the problem really occurs, when both labels are too long.

What is a preferred way to disable this or make detailTextLabel slightly wider? I want detailTextLabel to always show the entire label (it will be max 6 chars long, so it will fit); textLabel is fine as it is.

A: 

I think you might be better off using UITableViewDelegate's

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

and NSString's

- (CGSize)sizeWithFont:(UIFont *)font forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode

to change the height of the cell so it will fit. You should also add

 cell.detailTextLabel.numberOfLines = 0;
 cell.textLabel.numberOfLines = 0; 
Joe Cannatti
I tried text wrapping, but the detailLabel still gets obscured. Sometimes it appears shortened, and for long items not at all.
Ziga Kranjec
how about cell.detailTextLabel.numberOfLines = 0; and cell.textLabel.numberOfLines = 0; ?
Joe Cannatti
A: 

You can look at lineBreakMode and adjustsSizeToFitWidth properties of UILabel; if you use the latter, it's a good idea to set minimumFontSize as well.

It is also possible to set the frame of the different labels inside standard cells, but the most flexible solution is to lay out your cells in a separate nib.

Paul Lynch