【问题标题】:Change the tab (\t) length when using stringWithFormat?使用 stringWithFormat 时更改制表符 (\t) 长度?
【发布时间】:2014-03-14 10:35:35
【问题描述】:

我想在函数 stringWithFormat 中使用\t 时指定制表符长度或制表位:

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

我已经尝试在制表符后使用退格键,但这不起作用:

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

使用多个空格代替\t 不是一个选项,因为\t 之前的文本具有不同的宽度,具体取决于字符。

【问题讨论】:

标签: ios objective-c stringwithformat tabstop


【解决方案1】:

没有。制表符的显示不在 NSString 的控制范围之内。

如果你正在使用 UITextView 等 Cocoa API 来显示字符串,你可以使用 NSAttributedString 和 NSParagraphStyle 来设置显示的制表位。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-03
    • 1970-01-01
    • 1970-01-01
    • 2013-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多