It appears that stringWithFormat
ignores the sizing requests of the %@
format specifier. However, %s
specifier works correctly:
NSString *test = @"test";
NSString *str = [NSString stringWithFormat:@"%10s", [test cStringUsingEncoding:NSASCIIStringEncoding]];
NSLog(@"'%@'", str);
This prints ' test'
.