Ganesh Somani
Ganesh Somani

Reputation: 2360

UILabel truncate even when it has remaining lines

Current Behaviour

I have a multiLine UILabel with a Rectangular frame of a particular size. The font and all is so set that it will display a MAX of three lines and beyond that it will truncate.

Exceptional Behaviour

Exceptional behaviour is that sometimes I do have a complete Line or Two remaining but the line truncates. This is because the word at the end of the line is too Big to fit in the end of that line.

Expected Behaviour

I wish that the UILabel fills to all three Lines and then truncate.

This is my current code

[_detailedTextLabel setNumberOfLines:0];
[_detailedTextLabel setLineBreakMode:UILineBreakModeTailTruncation];
[_detailedTextLabel setAdjustsFontSizeToFitWidth:YES]; 

Upvotes: 4

Views: 4732

Answers (2)

Michał Ciuba
Michał Ciuba

Reputation: 7944

Use another line breaking mode.

[_detailedTextLabel setLineBreakMode:NSLineBreakByWordWrapping];

and also ensure that label has proper height (given that width is already set):

CGSize size = [_detailedTextLabel sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)];
_detailedTextLabel.frame = CGRectMake(0, 0, size.width, size.height);

Upvotes: 3

Dharmbir Singh
Dharmbir Singh

Reputation: 17535

Try to use this one. You need to write these two line.

label.lineBreakMode = UILineBreakModeWordWrap;
label.numberOfLines = 0;

Upvotes: 1

Related Questions