문제

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