Madan Mohan
Madan Mohan

Reputation: 8810

I'm getting problem when setting the height of label dynamically

I'm setting the tableView cells height dynamically according to labels height and labels height according to text. It is working fine when I had given text with spaces (ex: This is Question for stackoverflow). But when I'm entering text of length two lines without spaces(ex ThisisQuestionforstackoverflow) . It is taking two lines and the text is starting from second line and cutting at the end.It taking first line full space and second line like(ThisisQuestionfor.....).

I'm using methods

In cellForRowAtIndexPath

float productNameHeight = [DetailsViewController calculateHeightOfTextFromWidth:warObj1.productName :valueFont : valueWidth :UILineBreakModeWordWrap];
UILabel *productNameValue = [[UILabel alloc] initWithFrame:CGRectMake(xCoordinateStartLocatioForValue,yCoordinateStartLocation,valueWidth,productNameHeight)];

Can u plz help me quickly.Thanks in advance

Upvotes: 1

Views: 348

Answers (2)

VdesmedT
VdesmedT

Reputation: 9113

If there are no spaces in you text, be sure to use UILineBreakModeCharacterWrap or UILineBreakModeClip when both calculating the size of the UILabel and for the lineBreakMode property of the UILabel itself.

Upvotes: 0

deanWombourne
deanWombourne

Reputation: 38475

What's the line break mode for the label and how many lines are you allowing it to have?

You might be correctly setting the height of the label but then telling to draw all the text on one line :)

You should check that the number of lines in the label is 0 (which means as many as needed) and the line break mode is set to character break. (It sounds like it's set to truncate end at the moment).

Upvotes: 0

Related Questions