Вопрос

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.

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top