3

My problem is almost similar to this setting size to fit displays all the text in the label but it overlaps the other cells in table view as the height of the cell is different. to calculate the height I am currently using this method

+(CGSize)CommentSize:(NSString*)comment {

return [comment sizeWithFont:[UIFont boldSystemFontOfSize:messageTextSize] constrainedToSize:CGSizeMake(265, CGFLOAT_MAX) lineBreakMode:UILineBreakModeWordWrap];
}

It calculates the height of the text properly but the extra height(6 pix) that occupied by the emoji is not being added to the message height.

I also tried to set the text to another label made it sizetofit and get the height and pass it like this but it gives the same height as the above constrained method

+(CGSize)CommentSize:(NSString*)comment {

    UILabel *reviews = [[UILabel alloc]initWithFrame:CGRectMake(14, 13,265,30)];//Set frame
    reviews.numberOfLines=0;
    reviews.lineBreakMode = UILineBreakModeWordWrap;
    reviews.font = [UIFont boldSystemFontOfSize:14];
    reviews.text = comment;
    [reviews sizeToFit];

    CGFloat reviewlblheight = reviews.frame.size.height;

    CGSize maxlblSize = CGSizeMake(265,reviewlblheight);
    return maxlblSize;

}

how can i calculate the height. please help guys.

Found another link related to this issue https://github.com/mattt/TTTAttributedLabel/issues/82. Tried to implement the solution as suggested by mooshee. but couldn't solve the issue. can any one suggest how can i solve this.

Solution

A small edit to the second code snippet above solved the issue - Change the UILabel to TTTAttributelabel the height calculated using TTT and UIlabel are different.

Any one else who face the same issue can use the second code snippet. I am not sure whether it is correct approach are not but it solves the problem.

Thank you.

Community
  • 1
  • 1
vamsi575kg
  • 594
  • 1
  • 7
  • 23

1 Answers1

-3

Check with this code...

CGRect labelFrame = label.frame;  
labelFrame.size = [label sizeThatFits:CGSizeMake(100, 9999)];  
[label setFrame:labelFrame];
Mike
  • 737
  • 1
  • 6
  • 14
  • Increase the height of this label and try : UILabel *reviews = [[UILabel alloc]initWithFrame:CGRectMake(14, 13,270,300)]; – Mike Jul 24 '13 at 05:27
  • Did you use the textfield or textview for entering a input ? – Mike Jul 24 '13 at 06:48
  • I think you have to add the extra 6pix per line, so first count the no.of line then add the 6*no.of.line. AND the second option is the increase the your font size up to 6pix. :) – Mike Jul 24 '13 at 08:02
  • Yes i do get that idea. but the issue with that is if emojis are not there in the text it will show a lot of white space. Increasing the font size to 6pix is not a good idea (for my case). any how i made some work around and got the solution i will post it soon. Thank you very much @mindfreak – vamsi575kg Jul 24 '13 at 10:35