0

I'm changing UILabel height based on text. It works great, but i found one case that just won't load if the font size is bigger than 19.0f. It's okay if I change it, but I gave the user option to change the font size, so...

It starts overlapping views, messing views, here is example: enter image description here

Here is code I'm using to resize the label:

-(float)resizeToFit{
    float height = [self expectedHeight];
    CGRect newFrame = [self frame];
    newFrame.size.height = height;
    [self setFrame:newFrame];
    return newFrame.origin.y + newFrame.size.height;
}

-(float)expectedHeight{
    [self setNumberOfLines:0];
    [self setLineBreakMode:UILineBreakModeWordWrap];

    CGSize maximumLabelSize = CGSizeMake(self.frame.size.width,9999);

    CGSize expectedLabelSize = [[self text] sizeWithFont:[self font] 
                                            constrainedToSize:maximumLabelSize
                                            lineBreakMode:[self lineBreakMode]]; 
    return expectedLabelSize.height;
}

Thank you!

Devfly
  • 2,495
  • 5
  • 38
  • 56
  • It's hard to tell what's happening in that screenshot. Perhaps you could post a picture of what it's supposed to look like. Also, are you familiar with the `sizeThatFits:` message? – rob mayoff Oct 26 '12 at 00:22
  • if you can use tableview then try with my this answer given here : [http://stackoverflow.com/a/12600584/1538079][1] – Niru Mukund Shah Oct 26 '12 at 05:29

0 Answers0