Imagine a UILabel, which is 200 pixels wide and 50 pixels high. The label has text inside, and the label makes the text smaller so that it fits into the label. But now, how would you get the size of that UIFont how it is visible in the label? Lets imagine the font size was given with huge 100, and the label squeezes it down to 15. And then, you want to make some other labels with little text, which has same font size. Is there a way to obtain the UIFont's font size after getting squeezed by the label?
views:
891answers:
1
+4
A:
If you pass the size of the UILabel and the breakMode, etc. to:
CGSize size = [label.text sizeWithFont:label.font minFontSize:10 actualFontSize:&actualFontSize forWidth:200 lineBreakMode:UILineBreakModeTailTruncation];
actualFontSize should be what you are looking for.
mahboudz
2009-09-06 10:21:10
So actualFontSize would be a CGSize which I pass by reference to that method?
HelloMoon
2009-09-06 13:26:45
Yes. In C and Obj C, a function is restricted in how it can return values. Arguments you pass to a function are evaluated and their value is pushed onto the stack, before the function is called. The function gets only those values and can't relay a return value in them. Unless what is pushed is a pointer, in which case the function can use pointer to write to its address and modify it. I'm oversimplifying - here actualFontSize is one of the returned values of the function (method).
mahboudz
2009-09-06 18:02:20