1

I would like to specify a tab length or tab stops when using \t in the function stringWithFormat:

buttonText3 = [NSString stringWithFormat:@"D:\t%ld:%02ld" , hoursAndMinutesDay.hours,hoursAndMinutesDay.minutes];

I have already tried to use a backspace after the tab but this does not work:

[NSString stringWithFormat:@"D:\t%c%ld:%02ld", 0x0008, hoursAndMinutesDay.hours,hoursAndMinutesDay.minutes];

Using a number of spaces instead \t is not an option since the text before \t has different widths depending on the characters.

DrummerB
  • 39,814
  • 12
  • 105
  • 142
John
  • 8,468
  • 5
  • 36
  • 61
  • 1
    What are you doing with the string after you create it (what renders it to the screen)? – Wain Mar 14 '14 at 10:37
  • 1
    http://stackoverflow.com/questions/6699930/how-can-i-use-the-t-tab-operator-to-format-a-nsstring-in-columns and http://stackoverflow.com/questions/6860633/nsstring-stringwithformat-with-tabs-instead-of-spaces – iPatel Mar 14 '14 at 10:43
  • @iPatel He said spaces won't work for him though. – DrummerB Mar 14 '14 at 10:48
  • @Wain: I want to display it in an UITextLabel. – John Mar 14 '14 at 17:09
  • You can always get the length of the string before and decide how many spaces to add... – Wain Mar 14 '14 at 17:30
  • @Wain: The individual characters have different widths. – John Mar 15 '14 at 07:33

1 Answers1

3

There is not. Display of tab characters is outside of NSString's control.

If you are using Cocoa API such as UITextView to display the string, you may be able to use NSAttributedString and NSParagraphStyle to set tab stops for display.

Greg Parker
  • 7,972
  • 2
  • 24
  • 21