tags:

views:

54

answers:

1

The documentation is hard to interpret on this topic. Does this value return me how many characters the calculated format string will contain? Or does it tell me how big actually that string is? Or can I tell it how big (in unit squares or "pixels") the output should be?

Maybe someone can point out what this methods do...

+1  A: 

The -formatWidth getter method tells you how many characters the string will contain. The -setFormatWidth allows you to set that width.

The 'drawInRect' NSString extension can be used to constrain a string to a specific rectangle size.

Those same extensions have a method called 'sizeWithFont' that will tell you how big the rectangle needs to be to hold the string given a certain font.

See: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/NSString%5FUIKit%5FAdditions/Reference/Reference.html

Jack Cox
What happens if I tell it to have formatWidth=5, but there are more characters needed? What's the point of this?
HelloMoon
From my reading of the documentation (I agree that it's a bit vague) that it sets the number of padding characters that may be applied. I don't know what it does if the format is not large enough for the number. I would right a little snippet of code to make a formatted string and step through it with the debugger and see what it does with a numeric overflow situation.jack
Jack Cox
I've tried: When formatWidth is set to 3, but you have 7 characters in the output, it ignores that formatWidth. But when formatWidth is 7, and you have only 3 characters in the output, it will print 4 stars (*) in front of it to fill it up.
HelloMoon