Question

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!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top