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