Then you could use the stringSize however you want, the key is in 9999 as a height.
You would rarely find any text view rect with more than 9999 as a height. Unless if it's an article or something.
Currently, I can not find any way to calculate it without constraint.
Last edited by mnemonic_fx; 12-30-2008 at 12:37 AM.
This routine do not works very well, probably due to some bug.
The calculated frame size is not correct when you have letters that go below the baseline. The string aaaaa will be fine, but not aapqg, because qpg have pixels below the base line.
This routine do not works very well, probably due to some bug.
The calculated frame size is not correct when you have letters that go below the baseline. The string aaaaa will be fine, but not aapqg, because qpg have pixels below the base line.
Oh great.
What are the errors like? Does the frame size it gives you clip the descenders of the characters on the bottom row?
I haven't looked into fonts in Cocoa, but it should be possible to query the font for the leading value at the current size and style, and round the answer you get back up to the next multiple of the total font height (height + leading). Even simpler, you could just add myfont.descender to the height you get back from the call to sizeWithFont: constrainedToSize:.
Typically you want table rows to be a minimum of 44 high. Also, I find I usually add some margin also. If LunarMoon is correct I've noticed this problem since I'm always adding at least 20 pixels to the height anyway.
This is also my case. I am adding exactly 20 pixels too!!!! If you want to see the bug just add the text to the UITextView programatically as
Code:
[box setText: @"apqgbADF"];
and then use the code by mnemonic_fx
To see the full effect paint the box yellow before using the code or make it clip on the boundary. All letters with pixels below the baseline will be cut, i.e., it will clip the descenders of the characters on the bottom row.
I cannot believe Apple left behind something so simple and so basic as centering a &%$&#%$&% text vertically! We have to build 10,000 lines of code using sometimes buggy code to center a text on a box.
This remembers me the nightmare you have to pass to center a /&%%%#/ text horizontally and vertically (in all browsers) using CSS in HTML? What is wrong with these guys creating programming languages and standards? They build cars but always forgot to put the steering wheels.
I cannot believe Apple left behind something so simple and so basic as centering a &%$&#%$&% text vertically! We have to build 10,000 lines of code using sometimes buggy code to center a text on a box.
...this from the guys that created enough NSString methods to strangle a Clydesdale
Ahh... one must understand the Apple "mindset"...
1) The impossible... we deliver!
2) The difficult... we make easy!
3) The basic... we ignore!
unbelievable.... and BTW this Objective-C language oficially used to develop the applications is the most insane and complex language I ever used. I can understand the language without problems but I have sanity to see it very complex and not open to the everyone.