I have a slider, bind it with text field. It is possible automatically transform value to this format: Example 01 02 03 04 05 06 .. 13 14 15 ..? Thanks!
Asked
Active
Viewed 140 times
1
-
2What about using formatter? – Anoop Vaidya Jan 09 '13 at 14:13
1 Answers
2
Anoop is right. Create an NSNumberFormatter, and setting its minimumIntegerDigits to 2 will add a leading zero to single-digit numbers.
// Create an NSNumberFormatter that will add a leading 0 to single-digit numbers.
NSNumberFormatter* leadingZeroNumberFormatter = [NSNumberFormatter new] ;
leadingZeroNumberFormatter.minimumIntegerDigits = 2 ;
// Attach the NSNumberFormatter to your NSTextField
textField.formatter = leadingZeroNumberFormatter ;
The above example will take 6.27
and return 06
. If you'd rather see the .27
, check out the fractionDigits
methods in the NSNumberFormatter class reference.

Community
- 1
- 1

John Sauer
- 4,411
- 1
- 25
- 33
-
Big tanks! I think about NSValueTransformer, but NSNumberFormatter easiest way! – Nikolai Nagornyi Jan 09 '13 at 15:35