views:

12

answers:

1

I am using FontLabel to display varying lengths of texts in a custom font. I size the FontLabel using the following :

CGSize size = [myString sizeWithFont:[UIFont systemFontOfSize:[[[UIApplication sharedApplication] delegate] getFontSize]]
         constrainedToSize:CGSizeMake(290, 4000)
          lineBreakMode:UILineBreakModeWordWrap];

For some reason, this always presents a Fontlabel where the text starts at a different space from the top. Sometimes the text begins at the correct location. Other times, it appears either too high or too low.

Would appreciate some help in how to solve this issue.

A: 

I'm guessing here, but you are using it in a UITableViewCell ? The gotcha here is that tableviewcells are re-used, so you need to set every parameter of the cell that can possibly by adjusted by other previous instances of it. The first time you get a cell it is clean, the next time when it is re-used it may have settings and content from the previous use. This is especially a problem if you add subviews to your cell. Make sure you do that only when you create the cell, and not when you load it with content. If its not a tableviewcell, or this doesn't help, post a bit more context.

Andiih
Nope - not a tableview cell - regular text.
ok - any more context ? If you swap out that line of code for a fixed CGSize what happens ?
Andiih