3

I created custom UITableViewCell.

@interface AnswerCell : UITableViewCell
@property (nonatomic, retain) IBOutlet UILabel *textLabel;
@property (nonatomic, retain) IBOutlet UILabel *detailTextLabel;
@end

and set detailTextLabel.numberOfLines = 0;

        cell = [tableView dequeueReusableCellWithIdentifier:kAnswerIdentifier];
        if (cell == nil)
        {
            [[NSBundle mainBundle] loadNibNamed:@"AnswerCell" owner:self options:nil];
            cell=answerCell;
        }            

        cell.detailTextLabel.text = [self extractText:indexPath forLabelAttribute:kDetailTextLabel];
        cell.detailTextLabel.font = [self extractFont:indexPath forLabelAttribute:kDetailTextLabel];
        cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
        cell.detailTextLabel.numberOfLines = 0;

UILabel shows only first line of the text. But why?

UPDATE: My detailTextLabel's height = 21. What do I need to do? Do I need to change height = 1000?

Voloda2
  • 12,359
  • 18
  • 80
  • 130

3 Answers3

6

I guess you cannot show all text because label height is too small. You need to set required height depending on the text length.

See answer for Adjust UILabel height depending on the text

Community
  • 1
  • 1
beryllium
  • 29,669
  • 15
  • 106
  • 125
  • Thanks - I am resizing cells in a UICollectionView, expanding to show full text when tapped, and resetting the frame of the UILabel to the contentView.bounds was all it needed. – Adam Eberbach Dec 18 '12 at 11:07
  • If you do everything right and still have the problem. Exactly, check the height of the label. – Darius Miliauskas Dec 17 '21 at 13:52
1

You need to resize your UILabel .. calculate its height using -

[contentsStr sizeWithFont:[UIFont fontWithName:@"Helvetica" size:17.0f] 

and then resize it accordingly

you may need to change font and its size

Saurabh
  • 22,743
  • 12
  • 84
  • 133
1

If you have the width of the label, get the size of the string that would be required to show the string using the following method,

- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size

And set the size to the label.

The Apple documentation can be seen here.

Ilanchezhian
  • 17,426
  • 1
  • 53
  • 55