Hi
I am trying to make a label height fit the number of lines the label text has. I want the font size to be relative to the height of the component that holds the label. This is how I do it:
int fontSize = getHeight() / 16;
String s = label->getText();
int numberOfNewlineChars = 0;
CharPointer_UTF8 pChar = s.getCharPointer();
for (int i=0;i<s.length();i++)
{
if (*pChar++ == '\n')
{
numberOfNewlineChars++;
}
}
int b = label->getHorizontalBorderSize ();
int labelHeight = numberOfNewlineChars*((b*2) + fontSize);
label->setFont(fontSize);
label->setBounds(0, 0, getWidth(), labelHeight);
The label height does not fit the number of lines, what I see is that in the iPad simulator the height is to little to fit the text and in the iPhone 4 inch retina simulator there is to much empty space left after the text. Any ideas on what I am missing here is very welcome or suggestions on how to do this in other ways. Thanks.
best regards
John